javascript basic:

Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Reply

Join Date: Mar 2008
Posts: 56
Reputation: complexcodes is an unknown quantity at this point 
Solved Threads: 1
complexcodes complexcodes is offline Offline
Junior Poster in Training

javascript basic:

 
0
  #1
Nov 12th, 2008
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:
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <script type="text/javascript">
  2. var aValue;
  3. aValue=window.prompt("What is a's value?","value goes here");
  4. while(aValue==0 ||(isNan(aValue)))
  5. {
  6. aValue=prompt("Invalid number, enter a value again:", " value here");
  7. }
  8. var bValue;
  9. bValue=window.prompt("what is b's value?","value goes here");
  10. while(!(isNan(bValue)))
  11. {
  12. bValue=prompt("Invalid number, enter again:","value here");
  13. }
  14. var cValue;
  15. cValue=prompt("what is c's value?","value goes here");
  16. while(!(isNan(cValue)))
  17. {
  18. cValue=prompt("Invalid number,enter again:","value goes here");
  19. }
  20. </script>

How come it displays prompt box for a only? why am not I able to see prompt box for b and c?

Thanks,
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 954
Reputation: essential will become famous soon enough essential will become famous soon enough 
Solved Threads: 131
Featured Poster
essential's Avatar
essential essential is offline Offline
Posting Shark

Re: javascript basic:

 
0
  #2
Nov 14th, 2008
Hope you'll enjoy my simple demo, on how to get around with prompt boxes. Good day...

  1. <html>
  2. <head>
  3. <title><!--Sample--></title>
  4. <script type="text/javascript">
  5. <!--
  6. function abc()
  7. { var validValue = /^[1-9]{1,4}$/;
  8. var openValue = /[0-9]/;
  9. var a = prompt('What is a\'s value?', 'Value goes here!');
  10.  
  11. do { if (!validValue.test(a)) {
  12. alert('You must enter a valid number value not lower than 1!');
  13. a = prompt('What is a\'s value?', 'Value goes here!'); }
  14.  
  15. }
  16. while(!validValue.test(a));
  17. var b = prompt('What is b\'s value?', 'Value goes here!');
  18.  
  19. do { if (!validValue.test(b)) {
  20. alert('You must enter a valid number value not lower than 1!');
  21. b = prompt('What is b\'s value?', 'Value goes here!'); }
  22. } while(!validValue.test(b));
  23. var c = prompt('What is c\'s value?', 'Value goes here!');
  24. do { if (!openValue.test(c)) {
  25. alert('Invalid character value, please enter another value!');
  26. c = prompt('What is c\'s value?', 'Value goes here!'); }
  27. } while(!openValue.test(c))
  28. var abcValue = ( a.valueOf() * 1) + (b.valueOf() * 1) + (c.valueOf() * 1);
  29. if ( document.all && !document.getElementById) {
  30. document.all.total.innerText = abcValue; }
  31. else if (document.getElementById) {
  32. document.getElementById('total').innerText = abcValue; }
  33. }
  34.  
  35. /* To make it available to all major browsers' */
  36. if (window.addEventListener)
  37. window.addEventListener('load',abc,false);
  38. else if (window.attachEvent)
  39. window.attachEvent('onload',abc)
  40. else if (document.getElementById)
  41. window.onload = abc;
  42. //-->
  43. </script>
  44. </head>
  45. <body>
  46. <!-- Just to catch the total value of a b and c! -->
  47. <div id="total"></div>
  48. </body>
  49. </html>
Last edited by essential; Nov 14th, 2008 at 10:18 am.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the JavaScript / DHTML / AJAX Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC