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:

<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...

<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>
This article has been dead for over six months. Start a new discussion instead.