1 FUNCTION CALLED BY SEVERAL FORMS?

W

WindowFrog

Hello all. I have a page that via vbscript generates several forms...
each with a unique name. I would like to be able to call a single
JavaScript function (that checks the form date before submission) from
any of these forms, depending on which one is clicked. My code below is
where I am at, but it does not work. Any thoughts?

function checkForm(formName)
{
var error_string = "";

if (window.document.[formName].attach1.value == "" &&
window.document.[formName].attach2.value != "")
{
error_string += "Please select a matching Thumbnail image.\n";
}
if (window.document.[formName].attach1.value != "" &&
window.document.[formName].attach2.value == "")
{
error_string += "Please select a matching Large image.\n";
}
if (window.document.[formName].txtNameP.value == "")
{
error_string += "Please fill in the name of the photo.\n";
}
if (error_string == "")
{
return true;
} else {
error_string = "Check the form and complete the following:\n" +
error_string;
alert(error_string);
return false;
}
}

<font class='bodyText'><form name='frmSend1' method='post'
enctype='multipart/form-data' action='update_work.asp?no=100126&path=1'
onSubmit='var the_result = checkForm('frmSend1'); return
the_result;'><p><font color='#FFFF00'><b>UPDATE PHOTO
INFORMATION</b></font></p><p>Photo 1 (THUMBNAIL) pc_1.gif <input
name='attach1' type='file' size=35 class='inputText'><br>Photo 2 (LARGE
IMAGE) pc_2.gif <input name='attach2' type='file' size='35'
class='inputText'></p><p><input name='txtNameP' type='text'
class='inputText' size='30' maxlength='75' value='Uhm, no'> Photo Name
(i.e. South View or View from road)</p><p><textarea cols=30 rows=7
name='txtDescP' class='inputText'>testing</textarea> Photo Description
(255 character maximum. Not required)</p><input type='submit'
name='btnSubmit' value='Upload'
class='inputText'></font></font></form></font><font
class='bodyText'><form name='frmSend2' method='post'
enctype='multipart/form-data' action='update_work.asp?no=100126&path=2'
onSubmit='var the_result = checkForm('frmSend2'); return
the_result;'><p><font color='#FFFF00'><b>UPDATE PHOTO
INFORMATION</b></font></p><p>Photo 1 (THUMBNAIL) pc_2.gif <input
name='attach1' type='file' size=35 class='inputText'><br>Photo 2 (LARGE
IMAGE) <input name='attach2' type='file' size='35'
class='inputText'></p><p><input name='txtNameP' type='text'
class='inputText' size='30' maxlength='75' value='Hello Kitty, Meow'>
Photo Name (i.e. South View or View from road)</p><p><textarea cols=30
rows=7 name='txtDescP' class='inputText'></textarea> Photo Description
(255 character maximum. Not required)</p><input type='submit'
name='btnSubmit' value='Upload'
class='inputText'></font></font></form></font>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,999
Messages
2,570,243
Members
46,836
Latest member
login dogas

Latest Threads

Top