You need to move the :onclick => "ValidateForm()" to :onsubmit => "ValidateForm()" in the form_for line. Then when the ValidateForm returns false it will halt submission of the form.
You might want to consider using something like this: http://www.livevalidation.com/ There's a Rails plugin as well: http://github.com/porras/livevalidation/tree/master Cheers, Nicholas On Aug 4, 7:38 am, Md Fisa <[email protected]> wrote: > hi everybody... > I have a form_for in that, onclicking submit button i am calling > a javascript for validation.If validation fails that form_for doesnt do > anything.But even the validation fails it goes to the controller and > action. > here my code: > <%form_for :promotion_code, > :url=>{:controller=>"home",:action=>"create",:discount_id=>product.discount > .id,:id=>@ad.id} > do |f|%> > <%=f.radio_button :isemail,"true",:checked=>true%><b>Email > </b> > <%=f.radio_button :isemail, "false"%><b>Sms</b> > <%=f.text_field :email_or_mobile,:size=>20%> > <%=f.submit "Generate", :onclick=>"ValidateForm()"%> > <%end%> > > on validation failure it doesn't go to the :action > > please help me... > -- > Posted viahttp://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---

