Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Banned
    Join Date
    Jan 2012
    Posts
    26
    Thanks
    4
    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?

    Code:
    <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>
    Last edited by FlashDancer; 01-21-2012 at 08:01 AM.

  • #2
    Senior Coder
    Join Date
    Dec 2010
    Posts
    2,355
    Thanks
    11
    Thanked 558 Times in 551 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
    •