I am trying incorporate some javascript within the php below to pass a variable to the next page (checkout.php). It worked initially, but now I am having trouble executing this properly. Any tips?
echo '<div class = "row"><div class = "span 4 offset6"><select style="width: 130px;" name="shipping" class="span2">
<option value="0">7-9 days: FREE</option>
<option value="7">3-5 days: $7</option>
<option value="17">2 days: $17</option>
<option value="22">1 day: $22</option>
</select></div></div>';
}
echo '<script language="javascript">
function test()
{
var val=document.getElementById("select").value;
var hrf="checkout.php?options="+val;
document.getElementById("a_link").href=hrf;
}
</script>
<a href ="#" id="a_link" onclick="test();" class="btn btn-success" type="submit"><i class="icon-shopping-cart icon-white"></i> Add to Cart</a>';
EDIT: The problem I having is that when I click on the button, it stays on the same page instead of going to checkout.php with the option parameter.
Even when I change the first line of the javascipt to:
var val=document.getElementByName(“shipping”).value;
The page still stays the same. I’m assuming this is where the issue is but I odn’t know how to fix it.
Just do not incorporate JS within PHP. There is absolutely no point in this!
Just leave PHP mode and write JS as is: