...

View Full Version : Form Field Comparison



npala2001
08-02-2006, 07:38 PM
Hi Guys I am new to the world of javascript! I have three fields that I want validated on a form. Item3 cannot be smaller than Item2 and Item2 cannot be smaller than Item1. Below is what I had in mind:

Function validateForm()
{
If (Item3 < Item2)
alert="You must enter a bigger size for Item 3"
else
If (Item2 < Item1)
alert="You must enter a bigger size for Item 2
}
</script>

<form method="POST" action="Post.jsp" onsubmit="validateForm(this)">

angst
08-02-2006, 07:43 PM
where are you defining your variables? ie: Item1, Item2, Item3.

you need something like:

Function validateForm()
{
// var name // form name // input field name
var Item1 = document.myform.item1
var Item2 = document.myform.item2
var Item3 = document.myform.item3

If (Item3 < Item2){
alert=("You must enter a bigger size for Item 3");
} elseIf (Item2 < Item1){
alert=("You must enter a bigger size for Item 2");
}

}
</script>

<form method="POST" action="Post.jsp" name='myform' onsubmit="validateForm(this)">

npala2001
08-02-2006, 08:08 PM
I am not sure what you mean by defining my variables.

angst
08-02-2006, 08:13 PM
well, item1,2,3 and so on are all variables.

variables that mean nothing if they don't point to some data in your form or function. maybe post your html from here to continue.

npala2001
08-02-2006, 08:15 PM
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>PNC Form</title>
<Script type="text/javascript">
Function validateForm()
{
// var name // form name // input field name
var BA_PNC_6 = document.myform.BA_PNC_6
var BA_PNC_7 = document.myform.BA_PNC_7
var BA_PNC_5 = document.myform.BA_PNC_5

If (BA_PNC_6 < BA_PNC_7){
alert=("You must enter a bigger casing size");
} elseIf (BA_PNC_7 < BA_PNC_5){
alert=("You must enter a bigger tubing size");
}

}
</script>
</head>

<body>
<form method="POST" action="Post.jsp" name='myform' onsubmit="validateForm(this)">
<input type=hidden name="BV_SessionID" value="@@@@0661206313.1154442919@@@@">
<input type=hidden name="BV_EngineID" value="ccccaddigklgkefcefecfefdfmldhfg.0">

<input type=hidden name="stamp" value="3331895753">
<input type=hidden name="bhiFormName" value="BA_rpm_pnc">

<table width="95%" border="0" cellspacing="2" cellpadding="2">
<tr>
<th width="88%" scope="row"><div align="left"><strong>PNC Gas Response Chart</strong></div></th>
</tr>
</table>
<table width="600" border="1" cellpadding="5" cellspacing="0" bordercolor="#000000" bgcolor="#FFFFFF" id=table14 style="BORDER-COLLAPSE: collapse">
<tbody>
<tr bgcolor="#FFFFFF">
<td width="226" height="34" align=left valign=top>Enter your 4-3-1:</td>
<td align=left valign=top><INPUT name=BA_PNC_1 id="BA_PNC_1" size=40></td>
</tr>
<tr bgcolor="#FFFFFF">
<td valign=top align=left>Cost Center (Required):</td>
<td align=left valign=bottom><INPUT name=BA_PNC_2 id="BA_PNC_2" size=40></td>
</tr>
<tr bgcolor="#FFFFFF">
<td valign=top align=left>Region:</td>
<td align=left valign=bottom><br />
<select name='BA_PNC_3' id="BA_PNC_3" size='1'>
<option value='North America'>North America</option>
<option value='South America'>South America</option>
<option value='Eastern Hemisphere'>Eastern Hemisphere</option>
</select>
</td>
</tr>
<tr bgcolor="#FFFFFF">
<td colspan="2" align=left valign=top><strong>Complete the PNC Gas Response chart information:</strong></td>
</tr>
<tr bgcolor="#FFFFFF">
<td valign=top align=left>Well Name:</td>
<td align=left valign=top><INPUT NAME="BA_PNC_4" id="BA_PNC_4" tabindex="1" SIZE=36></td>
</tr>
<tr bgcolor="#FFFFFF">
<td valign=top align=left>Casing (in.):</td>
<td align=left valign=top><INPUT NAME="BA_PNC_6" id="BA_PNC_6" tabindex="4" SIZE=36></td>
</tr>
<tr bgcolor="#FFFFFF">
<td valign=top align=left>Tubing (in.):</td>
<td align=left valign=top><INPUT NAME="BA_PNC_7" id="BA_PNC_7" tabindex="4" SIZE=36></td>
</tr>
<tr bgcolor="#FFFFFF">
<td valign=top align=left>Bit Size:</td>
<td align=left valign=top><INPUT NAME="BA_PNC_5" id="BA_PNC_5" tabindex="2" SIZE=36></td>
</tr>
<tr bgcolor="#FFFFFF">
<td colspan="2" align=left valign=top><strong>Density:</strong></td>
</tr>
<tr bgcolor="#FFFFFF">
<td valign=top align=left>Tubing:</td>
<td align=left valign=top><INPUT NAME="BA_PNC_8" id="BA_PNC_8" tabindex="4" SIZE=28></td>
</tr>
<tr bgcolor="#FFFFFF">
<td valign=top align=left>Borehole:</td>
<td align=left valign=top><INPUT NAME="BA_PNC_9" id="BA_PNC_9" tabindex="4" SIZE=28></td>
</tr>
<tr bgcolor="#FFFFFF">
<td valign=top align=left>Formation:</td>
<td align=left valign=top><INPUT NAME="BA_PNC_10" id="BA_PNC_10" tabindex="4" SIZE=28></td>
</tr>
<tr bgcolor="#FFFFFF">
<td valign=top align=left>Formation Gas Density</font>:</td>
<td align=left valign=top><INPUT NAME="BA_PNC_11" id="BA_PNC_11" tabindex="4" SIZE=28></td>
</tr>
<tr bgcolor="#FFFFFF">
<td valign=top align=left>Gas Comp.(%):</td>
<td align=left valign=top><INPUT NAME="BA_PNC_12" id="BA_PNC_12" tabindex="4" SIZE=28></td>
</tr>
<tr bgcolor="#FFFFFF">
<td valign=top align=left>Comments:</td>
<td align=left valign=top><textarea name=BA_PNC_13 cols=30 rows=3 id="BA_PNC_13"></textarea></td>
</tr>
</tbody>
</table>
<table>
<tr>
<td>
<input type="submit" name="Submit" value="Submit">
<input type="reset" name="Reset" value="Reset Form">
</td>
</tr>
</table>
</form>
</body>
</html>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum