Click to See Complete Forum and Search --> : check two forms with one script...


weee
06-07-2004, 07:20 PM
Hi There.

I build a page that can contain up to 10 products with s simple form so the user can update the product name. the thing is that I'm trying to check out if the user entered a value into the field.

What I'm trying to do is giving the form name a like:
"productEdit1" and I'm giving the product id(1) to the JavaScript like that:
onSubmit="return checkProductEdit(1);"

This is the code:

function checkCompanyEdit(ddr){
if(productEdit+ddr.productName.value=="" || document.productEdit+ddr.productName.value.length<2)
{
document.getElementById('errDiv').innerHTML="2 letter at least";
document.productEdit+ddr.productName.focus();
return false;
}

}


The forms code:

<form name="productEdit1" method="post" action="#" onSubmit="return checkProductEdit(1);">
<b>שם המוצר:</b> בפלה<br>
<div id="errDiv">&nbsp;</div><br>
<input type name="productName" size="30" value="בפלה"><br>
<input type="submit" value="עדכן">
</form>

<br><br>

<form name="productEdit2" method="post" action="companyHandler.asp" onSubmit="return checkProductEdit(2);">
<b>שם המוצר:</b> מוצרי<br>
<div id="errDiv">&nbsp;</div><br>
<input type name="productName" size="30" value="מוצרי"><br>
<input type="submit" value="עדכן">
</form>


The problem is that it doesn't work. I don't know why?
any ideas?

Thanks guys!

Tage
06-07-2004, 10:02 PM
First, your function name doesn't match what the onSubmit event handlers are calling. Second, try using forms[] to do this. I added something to the errdiv id's and the getElementById(). Should be easy to spot.<html>
<head>
<script type="text/javascript">
<!--
function checkCompanyEdit(ddr){
if(document.forms["productEdit"+ddr].productName.value==""||document.forms["productEdit"+ddr].productName.value.length<2){
document.getElementById('errDiv'+ddr).innerHTML="2 letter at least";
document.forms["productEdit"+ddr].productName.focus();
return false}}
//-->
</script>
</head>
<body>
<form name="productEdit1" method="post" action="#" onSubmit="return checkCompanyEdit(1)">
<b>שם המוצר:</b> בפלה<br>
<div id="errDiv1">&nbsp;</div><br>
<input type name="productName" size="30" value="בפלה"><br>
<input type="submit" value="עדכן">
</form>
<br><br>
<form name="productEdit2" method="post" action="companyHandler.asp" onSubmit="return checkCompanyEdit(2)">
<b>שם המוצר:</b> מוצרי<br>
<div id="errDiv2">&nbsp;</div><br>
<input type name="productName" size="30" value="מוצרי"><br>
<input type="submit" value="עדכן">
</form>
</body>
</html>Tage

weee
06-07-2004, 11:00 PM
it's working great!