View Full Version : problem submitting a form through javascript

Jan 23rd, 2007, 07:04 PM
Hope fully this is a simple fix, but I'm trying to submit from within javascript:

My form html is:

<form id="dir">
<td>Your Starting Address:<br>(House # and Road name)<input type="text" name="address" /></td>
<td>Zip Code:<br><input type="text" name="zip" /></td>
<td colspan="2" style="text-align:center;"><input type="button" name="submit" value="Get Directions" onClick="javascript:getDirections()" /></td>

my javascript code is as follows:

function getDirections(){
var myform= document.getElementById("dir");
var endadd= myform.address.value + " " + myform.zip.value;
var strtadd = "8005 lafayette plain city rd 43064";

myform.action="http://maps.google.com/maps?saddr="+ endadd +"&daddr="+strtadd+"";

If i add a submit button it works, but I don't want to have two different buttons.

I've also tried other ways like document.forms[0].submit();

thanks in advance,

Jan 23rd, 2007, 07:13 PM

<input type="button" name="btnSubmit" id="btnSubmit" value="Get Directions" onclick="getDirections(this.form);" />

function getDirections(frm){
var endadd= frm.address.value + " " + frm.zip.value;
var strtadd = "8005 lafayette plain city rd 43064";

frm.action="http://maps.google.com/maps?saddr="+ endadd +"&daddr="+strtadd+"";

Jan 23rd, 2007, 07:52 PM
Thanks a lot that worked