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 5 of 5
  1. #1
    New Coder
    Join Date
    Nov 2009
    Posts
    29
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Drop Down Box Pain

    Hi

    This is my first query in this forum. My problem is simple, I just require 1 text box to be enable/disable depending on the option selected from drop down box by user.

    Visit the my site

    Here Company Certification: which has to be selected, if Other option is selected then Text box named Other will enable, and for the ISO2001 and None text box will disable.

    Here is the code which I embedded in Zen cart's php file
    PHP Code:
    <label class="inputLabel" for="company_certification"><?php echo 'Company Certification:'?></label>
    <?php
            
    echo "<select name=\"company_certification\">";
                echo 
    "<option value=\"ISO2001\">ISO2001</option>";
                echo 
    "<option value=\"OTHER\">Other</option>";
                echo 
    "<option value=\"None\">None</option>";
            echo 
    "</select>";
    ?>

    <?php echo "Other:"?>
        <?php echo zen_draw_input_field('other_certification'''zen_set_field_length(TABLE_ADDRESS_BOOK'customer_company_other_certification''40') . ' id="other_certification"') . (zen_not_null(ENTRY_COMPANY_TEXT) ? '<span class="alert">' ENTRY_COMPANY_TEXT '</span>'''); ?>
    I will thankful to you all for any suggestion or guidance

    Regards

  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    You want to do this using PHP? You'll have to refresh the page every time an option is selected. You probably want to use Javascript, which will enable/disable the text field immediately.

  • #3
    New Coder
    Join Date
    Nov 2009
    Posts
    29
    Thanks
    5
    Thanked 0 Times in 0 Posts
    Thank you Fumigator
    At last some one look on me...

    Yes I know this should happen at client side with JS or Ajax. I wrote a small JS for testing it works but don't know how to integrate with my PHP code

    Here is the JS
    Code:
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>Untitled Document</title>
    <script type="text/javascript">
    function change(val)
    {	
       if (val=="Other")
       {
    	document.getElementById("txt").innerHTML="<input type=\"text\" id=\"other\" name=\"other\"/>";
       }
       else
       {
    	document.getElementById("txt").innerHTML="<input type=\"text\" id=\"other\" name=\"other\" disabled/>";
       }
    }
    </script>
    </head>
    <body>
    <form name="f1">
    <select name="s1" onchange="change(this.value)" onchange="change(this.value)">
    <option value="ISO2000">ISO2000</option>
    <option value="ISI">ISI</option>
    <option value="Other">Other</option>
    </select>
    <div id="txt">
    	<input type="text" id="other" name="other"  disabled/>
    </div>
    </form>
    </body>
    </html>
    And PHP code already I gave in previous post

    I will be thankful if you can help me in integrating this JS with PHP

    Regards

  • #4
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    You really don't want to integrate PHP and JS code together, in my opinion. Keep your Javascript in a separate file and import it in using the "src=" attribute of the <script> tag.

    If you need to output your HTML from a PHP script, then do so, nothing wrong with that.

  • #5
    New Coder
    Join Date
    Nov 2009
    Posts
    29
    Thanks
    5
    Thanked 0 Times in 0 Posts
    OK I agree with your opinion. Can you give me some hint on code then I can move forward as I am not a very good in PHP.


  •  

    Posting Permissions

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