Click to See Complete Forum and Search --> : validation/hidden fields question


casa
04-16-2003, 05:00 PM
I have two forms with identical information that call the same javascript function. One form is for adding information and has 4 fields that are hidden and then other is for editing information and has those fields displayed in text fields. If I use the same javascript functions, will this if statement evaluate both the fields the same:
if (document.update.firstname.value.length == 0) {
alert ("Please enter the FIRSTNAME.");
document.update.firstname.focus();
return false;
}
The HTML:
<input type="hidden" name="firstname" value="<?=$_POST['firstname']?>">and <input type="text" name="firstname" size="25" value="<?=$rowS['firstname']?>">In the add script, there will be a value in firstname because I'm putting it there. In the edit script, it is being read in from the database, but the user could clear the form and thus blank out that field. So I guess what I'm asking is:
Will this javascript test bomb on the add (hidden field) script?

casa
04-16-2003, 06:50 PM
Dave, you totally lost me. The only difference in the form tag is the action. Form name is the same for both.<form action="editspeech.php" method="post" name="update" id="update">
and
<form action='addspeaker.php' method='post' name='update' id='update'>Each form has the same exact field names. The only difference is that the edit form is populated from a database and the add form has 4 hidden fields that are hard coded in from a login challenge. The javascript is in a .js file, not embedded in the html code.<SCRIPT LANGUAGE="JavaScript" SRC="./library/validate.js"></SCRIPT> I just want to know if I can use the same javascript function to validate both scripts.

DrDaMour
04-16-2003, 06:56 PM
i think a browser will get confused with those identicle id's if you aren't particularly set to using the same id's you could pass to your function the names of the forms, and then check each, of you can use teh forms array

eg:

function whatever(){

for(var i = 0;i < document.forms.length;i++){
document.forms[i]......

}