1

Hi

My problem is that I want Other textbox tobe deactivated when page loads, but when user selects Other drop down box of Company Certification: then Other textbox should be activated.

Please see here

Here is the PHP code which is displaying this page

<?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>': ''); ?>

And I found a java script which is this

<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>

Can I use this java script in my php code mentioned above.

Please help me...

Thank you all in advance

5
Contributors
13
Replies
14
Views
7 Years
Discussion Span
Last Post by maba001
0

Hi

...

Can I use this java script in my php code mentioned above.

Please help me...

Thank you all in advance

Not as shown in your code. In Javascript you would have to reference existing ID tags in the HTML code. So you would need something like

<p id="this_is_the_target"></p>

And then a Javascript code of

obj = getElementById('this_is_the_target');
obj.innerHTML = "Something new";

Please note that this is just pseudo code. So its not meant to be used literally. You could for example do some field substitution when you fill the innerHTML.

0

Not as shown in your code. In Javascript you would have to reference existing ID tags in the HTML code. So you would need something like

<p id="this_is_the_target"></p>

And then a Javascript code of

obj = getElementById('this_is_the_target');
obj.innerHTML = "Something new";

Please note that this is just pseudo code. So its not meant to be used literally. You could for example do some field substitution when you fill the innerHTML.

Another note - I reread your posting. The easier way would be to be to do getElementById directly on the input box and then set the enabled / disabled flag directly.

0

Hi

Thank you for your guidance but, I am using Zen cart and it is not possible to change all the code of Zen cart it may mess up the site.

If I forget about Javascript is it possible to do the job what I require purely in PHP

0

Hi
..
If I forget about Javascript is it possible to do the job what I require purely in PHP

I guess "No". The function you want to achieve is in the browser (purely client side). So it must be done at the client which means Javascript or some other client side language. But Javascript is probably the easiest one and the one which works across most browsers.

0

I guess "No". The function you want to achieve is in the browser (purely client side). So it must be done at the client which means Javascript or some other client side language. But Javascript is probably the easiest one and the one which works across most browsers.

While that is true there is a thing called ajax. I would suggest following an ajax tutorial where javascript can communicate with php after the page has loaded.

0

hello sir,i have a prob in code..i want to view uploaded resume file(Ex.-maurya.dco).format of resume is like same as doc file

0

Hi

Thank you for your guidance but, I am using Zen cart and it is not possible to change all the code of Zen cart it may mess up the site.

If I forget about Javascript is it possible to do the job what I require purely in PHP

please help me how to show a .doc file in same format in block or browser

0

Thank you again for your time and guidance can you provide me how to use javascript in my php code

0

Sounds like a bit heavy for just enabling / disabling another box.

Well if you want to populate information into a div box using data from another file or database after the page has loaded then ajax would be required as javascript does not have that functionality. If however it is to just hide and show the data again then you can use a mixture of javascript and css.

0

Thank you again for your time and guidance can you provide me how to use javascript in my php code

<html>
<head>
<script type="text/javascript">
function change(val) {
   textboxObj = document.getElementById('txtbox1');
   if (val == 'OTHER') {
	textboxObj.disabled = false;
   } else {
	textboxObj.disabled = true;
   }
}
</script>
</head>
<body>
  <form action="" method="get">
    <select id="combo1" name="combo1" onchange="change(this.value);">
      <option selected value="ISO2001">ISO 2001</option>
      <option value="OTHER">Other</option>
      <option value="ISI">ISI</option>
      <option value="NONE">None</option>
    </select>
    <br />
    <input type="text" name="txtbox1" id="txtbox1" disabled />
  </form>
</body>
</html>
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.