JavaScript - Completely Backwards! Tips Please?
Hello all,
I have written a javascript code to take the users Zip-Code, and make an alert come up with minimum purchases for free delivery. However, I have made this backwards from what I really need. I need an On-Load alert so customers can set their Zip-Code, and then print into a div the information needed. I also need this to store a cookie so the customer will not be forced to enter their information on every page visit. I have included a truncated portion of the script (it is over 850 lines) Code: function message() { zipcode = document.ZipCode.txtZip.value if (zipcode == 33820) { alert("Minimum purchase for delivery: $300.00" + '\n' + "For smaller orders, please visit Packitright.com at:" + '\n' + "http://packitright.com")} else if (zipcode == 33920) { alert("Minimum purchase for delivery: $235.00" + '\n' + "For smaller orders, please visit Packitright.com at:" + '\n' + "http://packitright.com")} else if (zipcode==34216) { alert("Minimum purchase for delivery: $150.00" + '\n' + "For smaller orders, please visit Packitright.com at:" + '\n' + "http://packitright.com")} else if (zipcode==33572) { alert("Minimum purchase for delivery: $150.00" + '\n' + "For smaller orders, please visit Packitright.com at:" + '\n' + "http://packitright.com")} else if (zipcode==32712) { alert("Minimum purchase for delivery: $300.00" + '\n' + "For smaller orders, please visit Packitright.com at:" + '\n' + "http://packitright.com")} else if (zipcode==34679) { alert("Minimum purchase for delivery: $150.00" + '\n' + "For smaller orders, please visit Packitright.com at:" + '\n' + "http://packitright.com")} else if (zipcode==33823) { alert("Minimum purchase for delivery: $300.00" + '\n' + "For smaller orders, please visit Packitright.com at:" + '\n' + "http://packitright.com")} Any assistance would be greatly appreciated. Similar TutorialsHi everyone, new here. I'm trying to write a program that displays what a user has entered, it processes it, and displays it backwards This is what I have so far, Code: <script type="text/javascript"> var input ("Please enter a sentance","") So really this is what it needs to display. "The sentance you entered are "Hi people"" "The sentance in REVERSE order are "elpoep iH" If anyone can help, it would be awesome, since I'm a noob at this. Hi, I can;t think what to search for but I need the following. I am running a form and if data is entered to the first text box, I want a warning message to show up, if they try to add data to any one of several other textboxes. tips on search terms would be great or a link to what might be some loosely appropriate code. bazz Hi. I've never used JavaScript, but I want to know if I can use JavaScript to prompt me to type in stuff and then organize it into a text file, complete with HTML tags. For example, suppose I had a template: The website < a href="#1"> is < green>#2< /green>. Then it would, ideally, prompt me, "Which website?", paste it into #1, "Safe or dangerous," and paste it into #2. So, if I answered "codingforums.com" and "safe," it should produce a page with text like this: The website < a href="codingforums.com"> is < green>safe< /green>. except with unbroken HTML tags. If this can be done, can you write the code or link to a good tutorial? Thanks in advance. Code: <%Function PF(num)%> <script type="text/javascript"> <!-- function toggleOff() { document.getElementById("floatingBox").style.display = "none"; } //--> </script> <div class="post_header" onClick="ToggleReply( <%=num%> )"> <div class="post_pmbutton" id="button_<%=num%>">[+]</div> <br clear="all"> </div> <div class="post_content" style="display: none;" id="content_<%=num%>"> <div id="floatingBox">some words here <a href="#&ID=<%=num%>" title="Close this box" onclick="javascript: toggleOff();">[I Agree]</a> </div></div> <%End Function%> It works fine, as long as it's the only one on the page. Problem is I potentially could have many dozens on any given page and the top one always works but the ones after do not I understand that I basically need to set a variable that is different for each rendition of the code but that is where I am stumped. I have a message ID from vb that I can pass to the javascript to get each iteration a unique ID I just don't know what to do with the number in javascript. I have NO clue about javascript Each iteration is hidden by default until an anchor is clicked. Please help clue this poor soul in 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> Okay so as you could tell by the unfamiliar name, I am a newbie. I have completed the codeacedmy Javascript course and while I know it's not the best for actually getting GOOD at at, it's still taught me a bit. I'm, working with a buddy of mine who is urging me to begin working on something ASAP so that we can start a project together. I suggest making a short RPG, but I'm unsure how I can begin with something like that and what I would need to work on. Or if you have any other projects you can suggest as a good first project to get my feet wet I would be extremely grateful for the help. Thanks in advance!
Hello Coding Forums, I am working on building a watch app for the Pebble smartwatch that works in combination with a Bluetooth light bulb that could trigger on and off functionality. I have bits of the source code from a the same bulb project someone started from another site that is coded Java, so I imported them into cloud pebble their java library. I've been working on this since last year and I'm wondering what at all could I be doing wrong. I get the "cards" to show up, but as far as a connection to the bulbs I have not established that yet. I've attached my source code and if anyone has any time to give me some pointers that would be appreciated massively. I know that Hubble worked on a similar project, to control lighting from a pebble smartwatch so I know it can be done. I've even tested this code with other developers who are experienced and they are also wondering why the connection does not take place. It would be really neat if I got this to work. Thank you everyone. Attached Thumbnails |