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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

disable Form Fields in CGI script with JavaScript

Status
Not open for further replies.

max1x

Programmer
Jan 12, 2005
366
US
In my CGI scripts, I've used external JavaScript calls for form validation.

Now I need to make an onClick java function call within the cgi (I'm assuming) script, that would enable or disable form fields based on the previous field. So if a user enters 1990 as their Year of Birth; they cannot enter e-mail address, without parents first contacting the site and electronically agreeing to terms & conditions. I have already build the server side validation, if JavaScript is bypassed, but need to make client side validation where ever possible.

Any advice?

Code:
print textarea ('yearOfBirth','','4','4');

== This below is what I'm thinkging how it would work?
print<<chkField;
function checkyearOfBith {
if thisFrom.checkyearOfBirth.search ??? {
thisForm.emailAddress.disable = true;
}
chkField

print textarea ('emailAddress,'','35','35');
 
You need to write a Javascript function to do this, triggered by an event on the year of birth text field.

Your CGI script will have to output the javascript code, or a reference to it. I find it easier to write my javascript in a text file and upload it separately. Then all my CGI scripts have to do is:
Code:
print '<script type="text/javascript" src="/scripts/somename.js></script>';
How you go about disabling te other field is a question for forum216 .

-- Chris Hunt
Webmaster & Tragedian
Extra Connections Ltd
 
Thank you Chris, most of my form is validated via external JS which I'm calling when the form tag is created and the onSubmit funtion calls the external JS.

Since this call needs to be done before the page is submited, I have made some mods to the page and have posted the question on JS forum as you suggested.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top