Related JavaScript

Rails obviously support client side validation. all you need is to put onsubmit event on whatever the form syntax you are using. below is an example:

<% form_tag ({:action => “new”}, {:onsubmit => “return validate();”}) %>

then your basic javascript goes like: function validate(){ if(document.getElementById(‘some_id’)==“”) alert(“specify first name”); }

You can put it anywhere… in the index.html.erb or in layouts or in some external javascript… in third case make sure that you are calling that javascript like

Ideally, javascript should be kept in head section of html, and for this you can use content_for tag. Read more about here: http://api.rubyonrails.org/classes/ActionView/Helpers/CaptureHelper.html#M001763

Thanks, Abhinav

<% form_tag({:action => "create"}, {:onsubmit => "return validate();"}) %> First name: <% end %>

I hope it will help

<% form_tag ({:action=>'create'}, {:onsubmit=>'return validate()'}) do %> <% end %>

I am sure this time it will surely help you

Tried again,

this time the output is a new page with

Unknown action

No action responded to create.

can see the attached file..............

Attachments: http://www.ruby-forum.com/attachment/4020/Screenshot.png

Error says it all: you do not have "create" action in your controller. Add it, it's not a javascript issue anymore.

Thanks, Abhinav

Dude your javascript is not getting loaded when your submit button is pressed… look carefully when you are calling javascript… try to alert some text to see what’s going wrong there

Interestingly, the browser apparently can load the page quicker if javascript is at the bottom.

http://developer.yahoo.com/performance/rules.html

-Jim http://www.thepeoplesfeed.com

James Englert wrote:

Interestingly, the browser apparently can load the page quicker if javascript is at the bottom.

Best Practices for Speeding Up Your Web Site - Yahoo Developer Network

That's a bizarre set of recommendations, especially given that Doug Crockford, Yahoo!'s own JS architect, recommends that JS not be mixed in with HTML at all.

-Jim http://www.thepeoplesfeed.com

Best,

Other than one specific case of a certain kind of landing page, I don't see a recommendation there to mix javascript and html.

They recommend combining multiple script resources into one, minifying etc.

I take putting the javascript at the bottom as putting the script tags referencing the separate script resource(s) at the bottom not inlining javascript in the page.