You could stick an onclick on the submit button. However, I suspect that you actually want an onsubmit on the form, ie form_tag('chap_two/index', :onsubmit => '...'). This will trigger if the user submits the form by hitting the enter key, whereas an onclick on the submit button obviously wouldn't
at last... it "half" works... i can call the function and it shows an
alert but the second command is not working... i assume it because the
gdir is not loaded...
at last... it "half" works... i can call the function and it shows an
alert but the second command is not working... i assume it because the
gdir is not loaded...
If you don't, then it's time to learn. Install the firebug extension for firefox and you'll have a pretty handy javascript debugger (and dom inspector, css viewer etc...)
Great, it works...
i've put these code below
"
<% form_tag "/chap_two/find", :onsubmit => "setDirections('san
fransisco', 'new york','en_US')" do -%>
<%= text_field_tag :address1, params[:address1] %>
<%= text_field_tag :address2, params[:address2] %>
<div><%= submit_tag 'Show' %></div>
<% end -%>
"
but what if i want to use my params[:address1] and params[:address2]
instead of 'san fransisco' and 'new york'...
i've tried these code below but it's not working...
I have this function below inside my public/application.js and i'm
wondering whether i can replace "San Fransisco" and "New York" in this
command "setDirections("San Francisco", "New York", "en_US");" with
session[:address1] and session[:address2]....???
Please can anyone show me how to do it...
"
function initialize() {
if (GBrowserIsCompatible()) {
alert("kyaaaaaaaa")
map = new GMap2(document.getElementById("map_canvas"));
gdir = new GDirections(map,
document.getElementById("directions"));
GEvent.addListener(gdir, "load", onGDirectionsLoad);
GEvent.addListener(gdir, "error", handleErrors);
setDirections("San Francisco", "New York", "en_US");
}
}
"
"
Great, it works...
i've put these code below
"
<% form_tag "/chap_two/find", :onsubmit => "setDirections('san
fransisco', 'new york','en_US')" do -%>
<%= text_field_tag :address1, params[:address1] %>
<%= text_field_tag :address2, params[:address2] %>
<div><%= submit_tag 'Show' %></div>
<% end -%>
"
but what if i want to use my params[:address1] and params[:address2]
instead of 'san fransisco' and 'new york'...
i've tried these code below but it's not working...
setDirections($F('address1'), $F('address2'), 'en_US') should do the
trick, assuming that those text fields have their id set to address1
and address2. Also (unless you want the form submitted as well as your
js called) you probably want a return false; at the end of your
onsubmit.