...

View Full Version : alert with two forms



joonstar
12-08-2004, 11:40 AM
<form action="key1_action.htm" method="post">
<input name="Key1"
value=""
type="text"
maxlength="20"
size="17"><br>

<input type="submit" value="Search key1">
</form>

<form action="key2_action.htm" method="post">
<input name="Key2"
value=""
type="text"
maxlength="20"
size="17"><br>

<input type="submit" value="Search Key2">
</form>


I have two forms in a page by the code above.

If user clicks the Search key1 sumbmit button without any entering,
I like to make an alert saying "key1, please."

And

If user clicks the Search key2 sumbmit button without any entering,
I like to make an alert saying "key2, please."


Can I do it with your help?

Thanks in Advance

glenngv
12-08-2004, 01:03 PM
<html>
<head>
<script type="text/javascript">
function validate(f, index){
var ele = f.elements["Key" + index];
if (ele.value == "")
{
alert("Key" + index + ", please.");
ele.focus();
return false;
}
return true;
}
</script>
</head>
<body>
<form action="key1_action.htm" method="post" onsubmit="return validate(this, 1)">
<input name="Key1"
value=""
type="text"
maxlength="20"
size="17"><br>

<input type="submit" value="Search key1">
</form>

<form action="key2_action.htm" method="post" onsubmit="return validate(this, 2)">
<input name="Key2"
value=""
type="text"
maxlength="20"
size="17"><br>

<input type="submit" value="Search Key2">
</form>
</body>
</html>

joonstar
12-08-2004, 01:23 PM
Thank you, your code works fine.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum