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
On Jan 8, 8:39 pm, Walter Lockhart <[email protected]> wrote:
> 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
>
> On Jan 8, 8:29 pm, Walter Lockhart <[email protected]> wrote:
>
> > 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
>
> > On Jan 8, 7:26 pm, Klaus Paiva <[email protected]> wrote:
>
> > > You can always return false and inside the else block, add this
> > > javascript that will submit the form:
> > > document.forms["myForm"].submit();
>
> > > On Jan 8, 3:19 pm, Walter Lockhart <[email protected]> wrote:
>
> > > > 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> *</strong></
> > > > td><td><%= text_field 'email', 'projectname', :size => 30 %></td></tr>
> > > > <tr><td style="width:50%;">Project Type:<strong> *</strong></
> > > > td><td><%= collection_select 'email', 'projecttype_id',
> > > > @projecttypes, :id, :name, { :include_blank => true } %></td></tr>
> > > > <tr><td style="width:50%;">Region:<strong> *</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 received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---