943,522 Members | Top Members by Rank

Ad:
Nov 12th, 2008
0

javascript basic:

Expand Post »
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,
Similar Threads
Reputation Points: 10
Solved Threads: 1
Junior Poster in Training
complexcodes is offline Offline
57 posts
since Mar 2008
Nov 14th, 2008
0

Re: javascript basic:

Hope you'll enjoy my simple demo, on how to get around with prompt boxes. Good day...

javascript Syntax (Toggle Plain Text)
  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.
Featured Poster
Reputation Points: 114
Solved Threads: 138
Posting Shark
essential is offline Offline
973 posts
since Aug 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in JavaScript / DHTML / AJAX Forum Timeline: Scrollable Drop Down Box?
Next Thread in JavaScript / DHTML / AJAX Forum Timeline: javascript for date using if condition





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC