| | |
javascript basic:
Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Mar 2008
Posts: 57
Reputation:
Solved Threads: 1
My program should allow to display prompt box to enter values for a b and c and should display message in prompt box like "invalid number please enter number again" for a if a ==0 and a is not a number. Same with b , but b can be equal to 0 and has to be a number not any characters. and c can be equal to zero and has to be a number not any characters.
here is my code so far:
How come it displays prompt box for a only? why am not I able to see prompt box for b and c?
Thanks,
here is my code so far:
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
<script type="text/javascript"> var aValue; aValue=window.prompt("What is a's value?","value goes here"); while(aValue==0 ||(isNan(aValue))) { aValue=prompt("Invalid number, enter a value again:", " value here"); } var bValue; bValue=window.prompt("what is b's value?","value goes here"); while(!(isNan(bValue))) { bValue=prompt("Invalid number, enter again:","value here"); } var cValue; cValue=prompt("what is c's value?","value goes here"); while(!(isNan(cValue))) { cValue=prompt("Invalid number,enter again:","value goes here"); } </script>
How come it displays prompt box for a only? why am not I able to see prompt box for b and c?
Thanks,
Hope you'll enjoy my simple demo, on how to get around with prompt boxes. Good day...
javascript Syntax (Toggle Plain Text)
<html> <head> <title><!--Sample--></title> <script type="text/javascript"> <!-- function abc() { var validValue = /^[1-9]{1,4}$/; var openValue = /[0-9]/; var a = prompt('What is a\'s value?', 'Value goes here!'); do { if (!validValue.test(a)) { alert('You must enter a valid number value not lower than 1!'); a = prompt('What is a\'s value?', 'Value goes here!'); } } while(!validValue.test(a)); var b = prompt('What is b\'s value?', 'Value goes here!'); do { if (!validValue.test(b)) { alert('You must enter a valid number value not lower than 1!'); b = prompt('What is b\'s value?', 'Value goes here!'); } } while(!validValue.test(b)); var c = prompt('What is c\'s value?', 'Value goes here!'); do { if (!openValue.test(c)) { alert('Invalid character value, please enter another value!'); c = prompt('What is c\'s value?', 'Value goes here!'); } } while(!openValue.test(c)) var abcValue = ( a.valueOf() * 1) + (b.valueOf() * 1) + (c.valueOf() * 1); if ( document.all && !document.getElementById) { document.all.total.innerText = abcValue; } else if (document.getElementById) { document.getElementById('total').innerText = abcValue; } } /* To make it available to all major browsers' */ if (window.addEventListener) window.addEventListener('load',abc,false); else if (window.attachEvent) window.attachEvent('onload',abc) else if (document.getElementById) window.onload = abc; //--> </script> </head> <body> <!-- Just to catch the total value of a b and c! --> <div id="total"></div> </body> </html>
Last edited by essential; Nov 14th, 2008 at 10:18 am.
![]() |
Similar Threads
- javascript code not working in firefox (JavaScript / DHTML / AJAX)
- Javascript / css menu image help, pls? (HTML and CSS)
- Please help a newbie - Javascript basic (JavaScript / DHTML / AJAX)
- Basic hover code question (JavaScript / DHTML / AJAX)
- Need help in design and javascript code for Dynamic form (JavaScript / DHTML / AJAX)
- Dynamically modifying the CSS attributes through Javascript (JavaScript / DHTML / AJAX)
- Learning JavaScript (JavaScript / DHTML / AJAX)
- recommendations for JavaScript learning resources? (JavaScript / DHTML / AJAX)
- Some Basic Code Hopefully (Help Needed) (HTML and CSS)
Other Threads in the JavaScript / DHTML / AJAX Forum
- Previous Thread: Scrollable Drop Down Box?
- Next Thread: javascript for date using if condition
| Thread Tools | Search this Thread |
Tag cloud for JavaScript / DHTML / AJAX
acid2 ajax ajaxexample ajaxjspservlets array autoplay beta blackjack boarder box browser captcha captchaformproblem cart close codes column css date debugger decimal dependent design developer dom download element embed enter error events firefox flash focus form frameworks game gears getselection google gwt gxt hiddenvalue highlightedword hint html ie7 iframe index java javascript javascripthelp2020 javascripts jquery jsp libcurl listbox maps marquee masterpage media menu mimic mp4 onerror onmouseover parameters paypal php player position post problem programming prototype rating redirect safari scale scriptlets search security select size software solutions sources starrating synchronous toggle tweet unicode variables w3c web webkit webservice window windowofwords xml





