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%>Email
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 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.
Thanks for yor reply …
I applied what you said.But its not getting.When i am giving :onsubmit
it doesn’t check for validation.It directly go to the action without
doing any validation.When validation return false it shouldn’t execute
the action.Your reply appreciated…Thanks verymuch
Thanks for yor reply …
I applied what you said.But its not getting.When i am giving :onsubmit
it doesn’t check for validation.It directly go to the action without
doing any validation.When validation return false it shouldn’t execute
the action.Your reply appreciated…Thanks verymuch
Hi, please post the Javascript that’s performing the validation?
<%form_for :promotion_code,
on validation failure it doesn’t go to the :action
product.discount.id,:id=>@ad.id },
section 23.5 of AWDwR 3ed.
Good luck,
-Conrad
The correct javascript handler to use would be onsubmit as Nicholas
Henry
recommends. Thus, the above
code has been corrected with this in mind as well as removing the typo.