...

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



FlashDancer
01-21-2012, 08: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">
<DIV>
<SELECT class="verdana" name="paymentmethod" onchange="this.form.action = this.value;">
<OPTION></OPTION>
<OPTION value="cheque/">Cheque</OPTION>
<OPTION value="visa/">Visa</OPTION>
</SELECT>
<BR>
<BR>
<INPUT type="submit" value="PROCEED">
</DIV>
</FORM>
<SCRIPT type="text/javascript">
document.forms["form"]["paymentmethod"].value = "<?php echo $_SESSION['order']['paymentmethod']; ?>";
</SCRIPT>

devnull69
01-21-2012, 04: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".



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum