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(){
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:


<% 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..............


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


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.


James Englert wrote:

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

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.



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.