I did the script so that I can pass the arguments in a function. Everything seems fine except when I entered all fields, it will check each field instead of only checking one field at a time. As I have 3 "OnClick" button, how do I make each check button to only check its own field instead of checking all other fields?
Any clue?
<script type="text/javascript">
<!--
function checkValue(a,b,c)
{
if ((x="button1"
&&(a!=''))
{
if(a>=5 && a<=45)
{
alert("'" + a + "' is Right!"
;
}
else
{
alert("'" + a + "' is wrong"
;
}
}
if ((x="button2"
&&(b!=''))
{
if(b>=-123 && b<=467)
{
prompt("'" + b + "' is Right!"
;
}
else
{
prompt("'" + b + "' is wrong"
;
}
}
if ((x="button3"
&&(c!=''))
{
if(c>=1 && c<=3)
{
window.status="'" + c + "' is Right!";
}
else
{
window.status="'" + c + "' is wrong";
}
}
}
-->
</script>
</head>
<body bgcolor="#FFFFFF" text="#000000">
<FORM NAME="myForm">
Enter a number between 5 and 45: <INPUT TYPE="TEXT" SIZE="10" NAME="field1">
<INPUT TYPE="BUTTON" NAME="button1" VALUE="Check&Alert" onClick="checkValue(document.myForm.field1.value,document.myForm.field2.value, document.myForm.field3.value)"><br>
Enter a number between -123 and 467: <INPUT TYPE="TEXT" SIZE="10" NAME="field2">
<INPUT TYPE="BUTTON" NAME="button2" VALUE="Check&Prompt" onClick="checkValue(document.myForm.field1.value,document.myForm.field2.value,document.myForm.field3.value)"><br>
Enter a number between 1 and 3: <INPUT TYPE="TEXT" SIZE="10" NAME="field3">
<INPUT TYPE="BUTTON" NAME="button3" VALUE="Check&Status" onClick="checkValue(document.myForm.field1.value,document.myForm.field2.value,document.myForm.field3.value)"><br>
</FORM>
</body>
</html>
Any clue?
<script type="text/javascript">
<!--
function checkValue(a,b,c)
{
if ((x="button1"
{
if(a>=5 && a<=45)
{
alert("'" + a + "' is Right!"
}
else
{
alert("'" + a + "' is wrong"
}
}
if ((x="button2"
{
if(b>=-123 && b<=467)
{
prompt("'" + b + "' is Right!"
}
else
{
prompt("'" + b + "' is wrong"
}
}
if ((x="button3"
{
if(c>=1 && c<=3)
{
window.status="'" + c + "' is Right!";
}
else
{
window.status="'" + c + "' is wrong";
}
}
}
-->
</script>
</head>
<body bgcolor="#FFFFFF" text="#000000">
<FORM NAME="myForm">
Enter a number between 5 and 45: <INPUT TYPE="TEXT" SIZE="10" NAME="field1">
<INPUT TYPE="BUTTON" NAME="button1" VALUE="Check&Alert" onClick="checkValue(document.myForm.field1.value,document.myForm.field2.value, document.myForm.field3.value)"><br>
Enter a number between -123 and 467: <INPUT TYPE="TEXT" SIZE="10" NAME="field2">
<INPUT TYPE="BUTTON" NAME="button2" VALUE="Check&Prompt" onClick="checkValue(document.myForm.field1.value,document.myForm.field2.value,document.myForm.field3.value)"><br>
Enter a number between 1 and 3: <INPUT TYPE="TEXT" SIZE="10" NAME="field3">
<INPUT TYPE="BUTTON" NAME="button3" VALUE="Check&Status" onClick="checkValue(document.myForm.field1.value,document.myForm.field2.value,document.myForm.field3.value)"><br>
</FORM>
</body>
</html>