PDA

View Full Version : problem submitting a form through javascript



ghostz00
Jan 23rd, 2007, 08: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">
<tr>
<td>Your Starting Address:<br>(House # and Road name)<input type="text" name="address" /></td>
</tr>
<tr>
<td>Zip Code:<br><input type="text" name="zip" /></td>
</tr>
<tr>
<td colspan="2" style="text-align:center;"><input type="button" name="submit" value="Get Directions" onClick="javascript:getDirections()" /></td>
</tr>
</form>


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+"";
myform.submit();
}

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,

nikkiH
Jan 23rd, 2007, 08:13 PM
Try:


<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+"";
frm.submit();
}

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