views:

31

answers:

1
function validate_request_form(){
   var valid = true;
   if ( document.request_form.firstname.value == "" )
   { alert ( "Please fill in first name" ); valid = false; return false; }  
   return valid;
 }

$j('#video-request-form').submit(function() {
    if (!validate_request_form() )
    return false;
});

I am using this code to validate my form. My form has id=video-request-form and the form name is request_form. This all works fine in latest FF, but can't get it to work in IE6...anyone?

+2  A: 

I suggest utilizing jQuery more instead of native JS. They are they to help. Try the following:

function validate_request_form(){
   var valid = true;
   if ( $j('#firstname').val() == "" ) {
     alert ( "Please fill in first name" ); valid = false; return false;
   }  
   return valid;
}

This assumes the field has an ID of firstname

Jason McCreary
it's not capturing the submit event, the form submits without hitting the function, I know because I put an alert('click'); in the submit function
vick
Change `$j()` to `$()`, unless you are running in conflict mode. But even that is `$J()` I believe. Note the case.
Jason McCreary
var $j = jQuery.noConflict();
vick
Sorry, couldn't remember the case. I have updated my answer to reflect it's usage. As far as the `.submit()` did you put the `alert()` as the first line?
Jason McCreary
You may also want to check out some jquery validation plugins: http://validity.thatscaptaintoyou.com/ or http://bassistance.de/jquery-plugins/jquery-plugin-validation/
campo
the problem is not the validation, the problem is that my submit function does not get triggered in IE6
vick