Problem with disable_with

Hi Group,

I have a registration.html.erb page with the following JavaScript at the top which I use to validate form fields:

<script type="text/javascript"> <!-- function validate(){ if ((document.myForm.email_projectname.value=="")|| (document.myForm.email_projecttype_id.selectedIndex<1)|| (document.myForm.email_region_id.selectedIndex<1))     {         alert ("You must fill in all of the required fields!")         return false     } else     return true; } //--> </script>

further down the page I have the form:

<% form_tag({:action => 'sendregistration'}, {:name => "myForm", :onSubmit => "return validate()"}) do -%>

<tr><td style="width:50%;">Project Name:<strong>&nbsp;*</strong></

<td><%= text_field 'email', 'projectname', :size => 30 %></td></tr>

<tr><td style="width:50%;">Project Type:<strong>&nbsp;*</strong></

<td><%= collection_select 'email', 'projecttype_id',

@projecttypes, :id, :name, { :include_blank => true } %></td></tr> <tr><td style="width:50%;">Region:<strong>&nbsp;*</strong></td><td><%= collection_select 'email', 'region_id', @regions, :id, :name, { :include_blank => true } %></td></tr>

etc.

<%= submit_tag "Send", :class => "submit", :id => "mysubmit", :disable_with => "Please wait..." %>

<% end -%>

When I click 'Send' without the required fields the 'Send' button is disabled and the text is replaced with 'Please wait...' which is as I expected. It also performs the 'validate' JavaScript function and discovers that the required fields are not provided and displays a popup window with the text 'You must fill in all of the required fields!'

When I click 'Send' with the required fields the 'Send' button is disabled and the text is replaced with 'Please wait...' which again is as I expected. However, the form does not Submit / Post, it just hangs.

What am I doing wrong? Would someone please help.

Thanks.

Regards

Walter

You can always return false and inside the else block, add this javascript that will submit the form: document.forms["myForm"].submit();

Hi Klaus,

thanks for your response. I tried this:

<script type="text/javascript"> <!-- function validate(){ if ((document.myForm.email_projectname.value=="")|| (document.myForm.email_projecttype_id.selectedIndex<1)|| (document.myForm.email_region_id.selectedIndex<1)     >>(document.myForm.email_message_body.value==""))     {         alert ("You must fill in all of the required fields!")         return false     } else { document.forms["myForm"].submit(); return false; } } //--> </script>

which I hope is what you were proposing in your response, but it still doesn't Post. It just hangs.

Regards

Walter

Hi Klaus,

now I'm really confused. When I remove the validation and use return true:

<script type="text/javascript"> <!-- function validate(){

document.forms["myForm"].submit(); return true;

} //--> </script>

It posts, no problem.

Any ideas?

Regards

Walter

Hi Klaus,

thanks for your help. The following code now works:

<script type="text/javascript"> <!-- function validate(){ if ((document.myForm.email_projectname.value=="")|| (document.myForm.email_projecttype_id.selectedIndex<1)|| (document.myForm.email_region_id.selectedIndex<1))     {         alert ("You must fill in all of the required fields!");         return false;     } else     {         document.forms["myForm"].submit();         return true;     } } //--> </script>

Thanks again.

Regards

Walter