<html>
<head>
<script>
function replacesrc() {
var array= new Array();
array[1,2,3,4]=document.getElementById("From").value.split(" ");
document.getElementById("map").src="https://maps.google.com/maps?f=d&source=s_d&saddr="+array[1]+"+"+array[2]+"+"+array[3]+",+North+Augusta,+SC&daddr=Hilton+Head+Island,+SC&geocode=FYn4_wEd4BQd-ym_ve9aOTP4iDGvGGPbsAEwOw%3BFfyU6wEdINAv-ymtGdOO3Hn8iDE9KKLreqblLA&aq=1&oq=hi&sll=33.623768,-80.925293&sspn=5.551464,10.129395&hl=en&mra=ls&ie=UTF8&t=m&ll=32.88718,-81.37587&spn=1.3416,1.24656&output=embed"
document.getElementById("test").value=array[1,2,3,4];
}
</script>
</head>
<body>
<iframe id="map" width="425" height="350" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="https://maps.google.com/maps?f=d&source=s_d&saddr=2000+Knobcone+Ave,+North+Augusta,+SC&daddr=Hilton+Head+Island,+SC&geocode=FYn4_wEd4BQd-ym_ve9aOTP4iDGvGGPbsAEwOw%3BFfyU6wEdINAv-ymtGdOO3Hn8iDE9KKLreqblLA&aq=1&oq=hi&sll=33.623768,-80.925293&sspn=5.551464,10.129395&hl=en&mra=ls&ie=UTF8&t=m&ll=32.88718,-81.37587&spn=1.3416,1.24656&output=embed"></iframe>
<br />From: <input id="From" type="text" /> <button onClick="replacesrc()">Directions</button><input id="test" type="text" value="test" />
<br /><small><a href="https://maps.google.com/maps?f=d&source=embed&saddr=2000+Knobcone+Ave,+North+Augusta,+SC&daddr=Hilton+Head+Island,+SC&geocode=FYn4_wEd4BQd-ym_ve9aOTP4iDGvGGPbsAEwOw%3BFfyU6wEdINAv-ymtGdOO3Hn8iDE9KKLreqblLA&aq=1&oq=hi&sll=33.623768,-80.925293&sspn=5.551464,10.129395&hl=en&mra=ls&ie=UTF8&t=m&ll=32.88718,-81.37587&spn=1.3416,1.24656" style="color:#0000FF;text-align:left">View Larger Map</a></small>
</body>
</html>
That is my code. It keeps passing it as undefined. Could someone help me out here? I’ve tried difference ways to fix this. But I still can not. From my point I did it right, cause I put a test function to see what it is sending and I get the same exact thing back, but when it put it in the src it put it as undefined.
Try this in place of the first two lines. Then access the elements starting at 0, so
array[0]is the first item,array[1]is the second, etc.And for the last line use this:
Why?
array[1,2,3,4]doesn’t do what you expect. It’s rather unintuitive. The commas here do not let you access multiple array indices.1,2,3,4is an expression using the oddball comma,operator three times. For an expressiona,bexpressionais evaluated and then thrown away. Nextbis evaluated and that becomes the value of the comma operator.So writing
array[1,2,3,4]is in fact identical witharray[4].