Hi All,
I am fresh to php.Please help me in following scenario.

I am trying to enable/disable a text by selecting 'Yes' or 'No' option of a combo box which is available on same page.

Note: It should only work with 'Yes'/'No' option selection not with a submit button click.

Kindly hep by sharing idea or any cod e vaialble.

Thanks in advance.

Recommended Answers

All 3 Replies

if you want to submit a page but you dont want to do that by submit button but on selection the combo box option then use

<select name='cmb' onchange='submit()' >
<option 1>
<option 2>
</select>

in this way when ever you will change your selection e.g from YESto NO or NO to YES it will submit your page and give you the value of the combo field. you can post that value and can use according to ur needs.

Hi ,
Thanks for your reply.
I donot want to submit the page in any condition because if I submit the page by selecting the item from combo it will wipe out/reset other field values on same page.

Please suggest any other alternative.

if you just want to enable/disable text field on selection then use following code

<html>
<body>
<form name="myform" action="" method="post">
<select name="mycmb" id="mycmb" onchange="enabledisabletext()" >
<option value="yes">YES</option>
<option value="no">NO</option>
</select>
<br /><br />
<input type="text" name="mytext1"  /><br />
<input type="text" name="mytext2" />
</form>
</body>
</html>

<script language="javascript">
function enabledisabletext()
{
	if(document.myform.mycmb.value=='yes')
	{
	document.myform.mytext1.disabled=true;
	document.myform.mytext2.disabled=false;
	}
	if(document.myform.mycmb.value=='no')
	{
	document.myform.mytext1.disabled=false;
	document.myform.mytext2.disabled=true;
	}
}
</script>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.