View Full Version : JavaScript won't change if an attribute exists. Why?

01-21-2012, 07:40 AM
$_SESSION['order']['paymentmethod'] equals "Cheque".
With the code bellow, I was expecting JavaScript to change the SELECT drop down menu to "Cheque", but it doesn't... However, when I remove the OPTION attribute value="cheque/", it works.

This appears to be because there is a conflict with the OPTION attribute value and the SELECT content value "Cheque".

Does anyone know how I can get around this issue?

<FORM action="" method="post" name="form">
<SELECT class="verdana" name="paymentmethod" onchange="this.form.action = this.value;">
<OPTION value="cheque/">Cheque</OPTION>
<OPTION value="visa/">Visa</OPTION>
<INPUT type="submit" value="PROCEED">
<SCRIPT type="text/javascript">
document.forms["form"]["paymentmethod"].value = "<?php echo $_SESSION['order']['paymentmethod']; ?>";

01-21-2012, 03:18 PM
There are two different things

One: The VALUE property "cheque/" of the <option> element which will become also the VALUE property of the surrounding <select> on selection

Two: The text content "Cheque" of the <option> element which is only visible on screen

So if you set the VALUE of the select to "Cheque", there is no corresponding <option> value to set the select to. This would only work if $_SESSION['order']['paymentmethod'] equaled "cheque/" instead of "Cheque".