JavaScript - General Advice...
Hello;
I'll begin like so many others before me, and apologize now if this post is in the wrong place, but since I don't exactly know what type of code I need, I'm not sure where to post this query. Let me preface this request by stating the obvious; I have almost no knowledge of coding. I've been watching tutorials for help with building a site for my small service-type business. I need coding that will allow my visitors to input their zip code to see if they reside in my service area. After they enter the zip and click the submit button, a page should pop up with one of two messages when they either are or are not in my service area. (I would undoubtedly need to list [somewhere in the coding] all the zip codes that are within my service area, and any zip codes not listed would bring up a message that the visitor is outside my service area.) I hope this makes sense, and someone can point me in the right direction. Thank you, in advance to any and all who respond, and keep in mind that you may have to dumb-down your responses for me to be able to understand. Similar TutorialsHi, I need help creating a function. It want it to: run when the page loads and every x seconds after. On loading I need it to connect to a db(preferably w ajax) and store results as variables I can reuse in other functions. And finally, after some math equations I can do, print the results on the page. I've been toying with this and I've realized its not as easy as I thought. Think I'm having problems with variable scope. Php is my main scripting language, of which I am fluent and have a working version of this. But I want it to run on the client side and relieve my server. Sorry if this is vague or incorrectly formatted, I'm on a phone browser. A guide or detailed demonstrations would be great, however pointing me in the right direction would me most apreciated. Hi, To put it bluntly I am a newbie to Javascript. I manage my own site using skills I have developed through learning code and need some help with debugging. My website is www.simplysafes.co.uk, in my IE it tells me I have an error with line 106 and char 2. Can anyone help me with this?? I would really appreciate it. Thanks in advance. James I've only just stated to teaching myself the general basics of web development, and I've hit a problem which I haven't been able to fix, even after some extensive research I haven't found a solution. The problem is not in the HTML I'm quite sure, hence why I deemed this to be the best place to post this. I'm sorry for wasting your time on something stupid like this, but I'm completely lost! Extra: I really couldn't think of a title that could describe this 'problem', my bad. Description: When clicking the calculate button nothing happens, but when I changed the code inthere to something easy (just print a line in a HTML paragraph) it worked. So by that I was able to deduce the problem lies somewhere in the Javascript. Code: <!DOCTYPE html> <html> <body> <div> <form> <fieldset> <h1>Quadratic equation</h1> a:<input type="text" id="a" name="a"><br><br> b:<input type="text" id="b" name="b"><br><br> c:<input type="text" id="c" name="c"><br><br> <button type="button" onclick="vkv()">Calculate</button> </fieldset><br> <fieldset> <p id="output">Answer appears here</p> </fieldset> </form> </div> <script> function vkv() { var a = document.getElementById(a); var b = document.getElementById(b); var c = document.getElementById(c); var D = pow(b,2) - 4 * a * c; if (D >= 0){ var x1 = (-b + sqrt(D)) / (2 * a); var x2 = (-b - sqrt(D)) / (2 * a); if (x1 == x2) { document.getElementById("output").innerHTML = "Value for x is:" + x1 + "."; } else { document.getElementById("output").innerHTML = "Values for x a " + x1 + " en " + x2 + "."; } } else { document.getElementById("output").innerHTML = "Discriminant is negative, " + D + "."; } } </script> </body> </html> Reply With Quote 02-03-2015, 10:31 PM #2 jmrker View Profile View Forum Posts Senior Coder Join Date Aug 2006 Location FL Posts 3,175 Thanks 39 Thanked 510 Times in 504 Posts Welcome to the forum... NOTE: I have not tested the logic of your code to see if it give the right answers, but this should get you started by at least seeing some results displayed. Primary problem was not using Math. before the math commands like pow and sqrt. Also, need quotes around id values in the document.getElementById statements And those statements require a value associated with the element Plus, it returns a string, hence the need for a Number() function or some other string to conversion. It is always a good idea to check the error console on most browsers to get an idea of the simple problems. That's where I found most of your errors. Code: <!DOCTYPE html> <html> <body> <div> <form> <fieldset> <h1>Quadratic equation</h1> a:<input type="text" id="a"><br><br> b:<input type="text" id="b"><br><br> c:<input type="text" id="c"><br><br> <button type="button" onclick="vkv()">Calculate</button> </fieldset><br> <fieldset> <p id="output">Answer appears here</p> </fieldset> </form> </div> <script> function vkv() { var a = Number(document.getElementById('a').value); var b = Number(document.getElementById('b').value); var c = Number(document.getElementById('c').value); var D = Math.pow(b,2) - 4 * a * c; if (D >= 0){ var x1 = (-b + Math.sqrt(D)) / (2 * a); var x2 = (-b - Math.sqrt(D)) / (2 * a); if (x1 == x2) { document.getElementById("output").innerHTML = "Value for x is:" + x1 + "."; } else { document.getElementById("output").innerHTML = "Values for x a " + x1 + " en " + x2 + "."; } } else { document.getElementById("output").innerHTML = "Discriminant is negative, " + D + "."; } } </script> </body> </html> Good Luck! I create a cookie on my homepage that tracks a number, the next time they view, js calculates another number and subtracts the saved number. Is the cookie value created accessible from a page other than the home page? i.E. I want to create a popup window that shows the calculation but i can seem to pass the variable generated from my external js script to the internal script/page. Am i able to call the getCookie class i created from the internal script even if the class is held in the external script or is it only accessible from the page that created the cookie? If its a dumb question, sorry im relatively new. I have a general javascript question. It may apply in this forum but maybe in the asp forum. I have a java applet on a site that I am building. If someone visiting the site doesn't have their javascript turned on, and chooses not to, is there some line of code that I can use that will detect that and replace the applet for an image I create? The site is developed in asp, but being that it is a javascript question, I thought it may apply here. Gary hi, I would like your help on the following matter. I have a JavaScript file currently reading from another site xml file in (utf-8) and I would like to store those data in my database which is in SQL_Latin1_General_CP1_CI_AS. Is there any function in JavaScript that can encode (convert) text from utf-8 to SQL_Latin1_General_CP1_CI_AS or any other way to do that? Hello, I'm new to this forum. I want to improve my ability to write JavaScript and am looking for a friendly place to find some constructive criticism and suggestions on my code. This script does not have any practical use (that I can think of); it calculates prime numbers. It is just an exercise. I am looking for suggestions on all aspects from the CSS/aesthetics to the HTML and of course the JavaScript. I posted the script here. One definite thing that bugs me is the cursor is not in the text field when the page loads. Also it would be better if the user had the option of hitting the return key in addition to the submit button. Suggestions appreciated. Code: <!DOCTYPE html> <html lang="en"> <head> <title>Prime Number Calculator</title> <style type="text/css"> form{ width: 200px; border: solid 3px blue; border-style: double; padding:5px; text-align:center; background-color:#eee; } #title{ text-align:center; border: solid 1px blue; background-color:#fff; margin:5px; padding:0px; } </style> <script src="jquery.js" type="text/javascript"></script> <script type="text/javascript"> var candidates = new Array(); function calculatePrimes(form){ var max = form.input.value; //Check to make sure input is a number if(isNaN(max)){ alert("Dude, you must enter a number!"); } for(i=2; i<=max; i++){candidates[i]=i;} var i=2; for(i=2; i<Math.sqrt(max); i++){ if (candidates[i]!=0){ var j=i*i; while(j<max){ candidates[j] = 0; j=j+i; } } } //Pull the primes out of the candidates i=2; var primesOut = ""; for(i=2; i<max; i++){ if(candidates[i]!= 0){ primesOut = primesOut + ((i>2)?", " : "" ) + candidates[i]; } } form.output.value = primesOut; } </script> <head> <body> <form> <h2 id="title">Prime-Number Calculator</h1> Check up to:<input type="text" name="input" size="5" value="100" \> <br /> <textarea rows="5" cols="20" name="output"></textarea> <input name="calc" value="Find!" type=button onClick="calculatePrimes(this.form)"> </form> </body> </html> Hi, as the title states, I'm trying to learn some basic javascript, more particularly, jQuery. I HATE having to "allow" active content to run on my IE browser. Is there a way to allow active content permanantly? Instead of having to click allow each time I refresh or reload my test pages? Also, IE keeps freezing or crashing when I run pages with scripts on them. Is this just my browser? or something to do with the active content permissions? Trying to google my questions, but no luck yet. Hi could someone please help?... I am a total beginner to javascript... but does anyone know of a code, including links to an image folder, for displaying 6 fullscreen images in random order without repeat for a given user? I've seen specific examples using shuffle on the site, but could anyone write a general code for any given images? Many thanks in advance On my home page, I have a video area. I have a Jquery script that adds a curtain overlay to the video and then draws the curtains open to reveal the video behind it. It works fine in Firefox, but not in IE or Safari, not sure about other browsers. Can someone help me fix this so it works in those browsers please? http://billboardfamily.com/?theme=DeepFocus Thanks. I currently have php site with a system of loading up 5 iframes on a page that target part of another website with recaptcha's so all 5 iframes auto scroll to the recaptcha box's. Now, my question is, is there any way to have it auto select the next iframe ready to type into the recaptcha box? Like, i have a list of 5 iframes & in iframe1 i type in the recaptcha words & press enter, then i want it to auto jump to the next iframe ready to type without having to click the text area box, is this possible & how? okay, so im planning on starting an online retail business and im fairly new to coding. i want to be able to sort the items for sale and then display them in order. i just need some help on where to start. i was thinking of using a server side script or xml or something to give the items values like rating=some number and then sort them from highest to lowest, then have the web page display the items in order. am i going about this in the right way? any suggestion would help
Hello! I have recently begun the creation of my online web designers portfolio and I have come across a small, yet easily correctable (I'm praying!) problem. The main problem is that when my site is visited for the first time, the site takes to long to load/create the cache! I have done things such as kept everything in external stylesheets etc, but one thing I believe is the cause is the images, there are so many so its understandable, what I was wondering is if its possible to create a preloading page, that will create the cache for the entire website?? Bearing in mind I have only four pages! Hi, I have been downloading and examining "gallery building" software and I find none of it links to an e-commerce option. Does anyone out there know the quickest way I can create a truly simple sales website which supplies a payment procedure for photos in an online gallery, thereby allowing javascript to #1 display a larger hover on mousover and #2 (on mouseclick) link photos (my gallery material) to an e-commerce component which offers a "payment procedure" to people visiting my gallery, specifically "bank transfer, credit card, check, PayPal etc." and will allow them to purchase my photos. The photos would be not the "large hover" ones watermarked with my own logo, but would be #3 the (presumably cached) clean, downloadable photos of a higher resolution represented by the watermarked photos and intended for sale. This would I assume then include a "download photo" page as part of the e-commerce "payment procedure" allowing non-watermarked photos cached safely outside the viewable gallery to be purchased. It sounds like such a breeze, (#1,#2,#3) and I find javascripting with little fragments of these codes, (have even been admiring the free code offered by several programmers which opens thumbnails on hover etc.) but none of it (#1,#2,#3) all stitched together. Anyone capable of this? Hey, Im really new to Java and ideally i would love a java guru to have a quick look at this and help me. I am using this script i found he http://www.javascriptkit.com/script/...ownpanel.shtml It is a real good script and have set it up on my site fine. However, i am using it for a login portal. But when the user clicks on anything on the page that has been brought down, it pops back up and away. Obviously this is not good for a login box. So i need to limit the expand/contract feature to the button only. Rather than the whole box. Now im sure its just re-shifting code around or add/removing a few lines of code. Ive spent the past 2 hours trying to look at this and still no look, so im calling for an expert to have a look. This is in my jkpanel.js file: Code: //Drop Down Panel script (March 29th, 08'): By JavaScript Kit: http://www.javascriptkit.com var jkpanel={ controltext: 'Login', $mainpanel: null, contentdivheight: 0, openclose:function($, speed){ this.$mainpanel.stop() //stop any animation if (this.$mainpanel.attr('openstate')=='closed') this.$mainpanel.animate({top: 0}, speed).attr({openstate: 'open'}) else this.$mainpanel.animate({top: -this.contentdivheight+'px'}, speed).attr({openstate: 'closed'}) }, init:function(file, height, speed){ jQuery(document).ready(function($){ jkpanel.$mainpanel=$('<div id="dropdownpanel"><div class="contentdiv"></div><div class="control">'+jkpanel.controltext,+'</div></div>').prependTo('body') kpanel.$mainpanel.click(function(){jkpanel.openclose($, speed)}) var $contentdiv=jkpanel.$mainpanel.find('.contentdiv') var $controldiv=jkpanel.$mainpanel.find('.control').css({cursor: 'wait'}) $contentdiv.load(file, '', function($){ var heightattr=isNaN(parseInt(height))? 'auto' : parseInt(height)+'px' $contentdiv.css({height: heightattr}) jkpanel.contentdivheight=parseInt($contentdiv.get(0).offsetHeight) jkpanel.$mainpanel.css({top:-jkpanel.contentdivheight+'px', visibility:'visible'}).attr('openstate', 'closed') $controldiv.css({cursor:'hand', cursor:'pointer'}) }) }) } } //Initialize script: jkpanel.init('path_to_content_file', 'height of content DIV in px', animation_duration) jkpanel.init('../ajaxexamples/login.html', '210px', 300) This in in my made .html page. Code: <script type="text/javascript" src="../ajaxexamples/jquery-1.2.2.pack.js"></script> <style type="text/css"> #dropdownpanel{ /*Outermost Panel DIV*/ position: absolute; width: 100%; left: 0; top: 0; visibility:hidden; } #dropdownpanel .contentdiv{ /*Div containing Ajax content*/ background: url(../images/sitestructure/dropdownbackup.png); background-repeat: repeat; color: white; padding: 20px; } #dropdownpanel .control{ /*Div containing panel button*/ border-top: 5px solid black; color: white; font-weight: normal; text-align: center; background: transparent url("../ajaxexamples/panel.gif") center center no-repeat; /*change panel.gif to your own if desired*/ padding-bottom: 3px; /* 21px + 3px should equal height of "panel.gif" */ height: 21px; /* 21px + 3 px should equal height of "panel.gif" */ line-height: 21px; /* 21px + 3px should equal height of "panel.gif" */ } </style> <script type="text/javascript" src="../ajaxexamples/jkpanel.js"> /*********************************************** * Drop Down Panel script- by JavaScript Kit (www.javascriptkit.com) * This notice must stay intact for usage * Visit JavaScript Kit at http://www.javascriptkit.com/ for this script and 100s more ***********************************************/ </script> Thanks, Hello New here and not a programmer by any stretch of the imagination .. need some help with the following code .. rather lots of help .. I apologise if this is ugly code .. but I don't know much yet. Code: <HTML> <HEAD> <SCRIPT LANGUAGE="JavaScript"> function addNumbers() { var val1 = parseInt(document.getElementById("value1").value); var val2 = parseInt(document.getElementById("value2").value); var val3 = parseInt(document.getElementById("value3").value); var val4 = parseInt(document.getElementById("value4").value); var ansD = document.getElementById("answer"); ansD.value = val1 + val2 + val3 + val4; } function calc() { var val5 = parseInt(document.getElementById("value5").value); var val6 = parseInt(document.getElementById("value6").value); var val7 = parseInt(document.getElementById("value7").value); var ansD = document.getElementById("answer2"); ansD.value = (val5 + val6 + val7)*100/(100-10); } function calc2() { var val8 = parseInt(document.getElementById("value8").value); var val9 = parseInt(document.getElementById("value9").value); var val10 = parseInt(document.getElementById("value10").value); var ansD = document.getElementById("answer3"); ansD.value = (val8 + val9 + val10)*100/(100-20); } function addNumbers1() { var val11 = parseInt(document.getElementById("answer").value); var val12 = parseInt(document.getElementById("answer2").value); var val13 = parseInt(document.getElementById("answer3").value); var ansD = document.getElementById("answer4"); ansD.value = (val11 + val12 + val13); } </script> <HEAD> <BODY <FORM NAME="Calc"> <TABLE BORDER=1> <TR> <TD> INCOME (GROSS) <br> Income = <input type="text" id="value1" name="value1" value=""/><br> Income = <input type="text" id="value2" name="value2" value=""/><br> Income = <input type="text" id="value3" name="value3" value=""/><br> Income = <input type="text" id="value4" name="value4" value=""/><br> <input type="button" name="Sumbit" value="TOTAL (GROSS)"onClick="javascript:addNumbers()"/> = <input type="text" id="answer" name="answer" value=""/> <br> <br> INCOME (NET) 10% <br> Income = <input type="text" id="value5" name="value5" value=""/><br> Income = <input type="text" id="value6" name="value6" value=""/><br> Income = <input type="text" id="value7" name="value7" value=""/><br> <input type="button" name="Sumbit" value="TOTAL GROSSED (@ 10%)" onClick="javascript:calc(2)"/> = <input type="text" id="answer2" name="answer2" value=""/> <br> <br> INCOME (NET) 20% <br> Income = <input type="text" id="value8" name="value8" value=""/><br> Income = <input type="text" id="value9" name="value9" value=""/><br> Income = <input type="text" id="value10" name="value10" value=""/><br> <br> <input type="button" name="Sumbit2" value="TOTAL GROSSED (@ 20%)"onClick="javascript:calc2()"/> = <input type="text" id="answer3" name="answer3" value=""/> <br> <br> <input type="button" name="TOTAL STATUTORY INCOME" value="TOTAL STATUTORY INCOME"onClick="javascript:addNumbers1()"/> = <input type="text" id="answer4" name="answer4" value=""/> <br> <br> </TD> </TR> </TABLE> </FORM> </BODY> <HTML> The first issue ... (as simply as possible .. remember very new to all this) how can I limit decimals to 2 places.. and prevent rounding. The second issue .. how can I get the TOTAL buttons to calculate without having to fill in numbers into each entry box... If it don't put "0s" it gives NaN. Ideally by the automatic entry of "0s" when the TOTAL button is pressed. Further issues as the coding progresses... Thanks.. Hey All, I've got the following site that loads great in FF and Chrome (no surprise), but is terribly slow in IE7. It's even quick in IE6, but not 7. Here's the site: http://www.hanshawengines.com/ Now I'm using JQuery in a couple places, but it's by no means nothing crazy. The page is fairly simple. I thought of preloading the main content images, but even after they are loaded in the cycle, the loading time is still slow. Any suggestions on how I could improve this would be greatly appreciated. Thanks. I'm new to programming in general and have had trouble deciding on a good starter project. I've decided to start with something that is (hopefully) pretty simple. I have about a dozen boxes full of vinyl records and would like to write a program to catalogue everything alphabetically by artist using prompts to ask for Album Title, Artist Title, and year. My question at this point is, is JavaScript a good way to do this? I have a fundamental knowledge of HTML, CSS, JavaScript and Ruby. I assumed JS would be the best way (that I know at this point) to do this project, but if I'm wrong, would love to hear it. What I don't understand at this point is how to output the information to a text file, or how to set up an interface to run the scripts. Any advice is very much appreciated. Hi, I need to create a subscription form with a pop up window. I would like to re-do the following html code so that it works with a JavaScript pop-up: Code: <form style="border:1px solid #ccc;padding:3px;text-align:center;" method="post" rel="nofollow" target="popupwindow" action="http://feedburner.google.com/fb/a/mailverify" onsubmit="window.open('http://feedburner.google.com/fb/a/mailverify?uri=PinkPigeon', 'popupwindow', 'scrollbars=yes,width=550,height=520');return true"> <p>Enter your email address:</p><p><input type="text" style="width:140px" name="email"/><input type="hidden" value="PinkPigeon" name="uri"/><input type="hidden" name="loc" value="en_US"/><input type="submit" value="Subscribe" /></p><p>Pink Pigeon Feed</p></form> if anyone can help that would be great thanks Will Hi All, I am looking to build a gallery similar to this one: http://www.designguru.co.za/pages/brand.php I am new to MooTools and don't know where to start, which plug ins etc.. Can anyone help me or just point me in the right directions Thanks in advance |