Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Confusion

Status
Not open for further replies.

Krus1972

Programmer
Mar 18, 2004
145
US
The script below is simple form validation and form submit. I would like to use this script by several different form names and unput box names on the same webpage. Passing the form name as the "form" variable, input box value as the "query" variable, and the target frame as the "target" variable into the function is the only way I can see how to do this.

The problem is, once they are passed into the function, what is the proper syntex to use the variables within the body of the script? Right now "form1", "query1", and "frame1" are specific names of only ONE document objects on the webpage. How do I use the variables I just passed into the function so that I can use this with more then one form on the same webpage?

Thanks for your help.


function framesubmit(form,frame,query)

{


// Check For a Valid Search
if(document.form1.query1.value==''){
alert("Invalid Entry")
return false;
}
if(document.form1.query1.value==' '){
alert("Invalid Entry")
return false;
}

if(document.form1.query1.value==' '){
alert("Invalid Entry")
return false;
}

var iChars = "!@#$%^&*()+=-[]\';,./{}|\":<>?";
for (var i = 0; i < document.forms["form1"].query1.value.length; i++) {
if (iChars.indexOf(document.forms['form1'].query1.value.charAt(i)) != -1)
{
alert("Invalid Entry - Enter only letters and numbers. Special characters are not allowed.")
return false;
}
}

// alert("Valid Search")


document.form1.target = frame1;
document.form1.action = "/fjobs.asp";
document.form1.submit();



}
 
Assuming form, frame and query variables contain the names of the target elements, you would need to use the forms, elements, and frames arrays to access the referenced objects.

document.frames[frame];
document.frames[frame].forms[form];
ocument.frames[frame].forms[form].elements[query];

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Behind the Web, Tips and Tricks for Web Development.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top