View Full Version : Drop Down Box Pain

03-11-2010, 06:35 AM

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 (http://www.oemxtrade.com/index.php?main_page=create_account)

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

<label class="inputLabel" for="company_certification"><?php echo 'Company Certification:'; ?></label>
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


03-11-2010, 05:44 PM
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.

03-12-2010, 04:00 AM
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

<html xmlns="http://www.w3.org/1999/xhtml">
<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\"/>";
document.getElementById("txt").innerHTML="<input type=\"text\" id=\"other\" name=\"other\" disabled/>";
<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>
<div id="txt">
<input type="text" id="other" name="other" disabled/>

And PHP code already I gave in previous post

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


03-12-2010, 05:34 PM
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.

03-13-2010, 03:59 AM
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.