Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Join Date
    Jan 2012
    Thanked 0 Times in 0 Posts

    JavaScript won't change if an attribute exists. Why?

    $_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']; ?>";
    Last edited by FlashDancer; 01-21-2012 at 09:01 AM.

  • #2
    Senior Coder
    Join Date
    Dec 2010
    Thanked 570 Times in 563 Posts
    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".


    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts