View Single Post
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