I need to enable a disabled text box through php.Please inform me about the errors in the following code:

<input type= "text" name ="ch1" disabled = "true"
<?
if ( $_GET["e"] == 3 )
echo "disabled = 'false' ";
?>
/>

Recommended Answers

All 14 Replies

This simply wouldn't work because this is how your source would look like.

<input type= "text" name ="ch1" disabled='true'
disabled='false'/>
<input type= "text" name ="ch1" <?php if(!S_GET['e'] == 3)  {echo "disabled=\"disabled\"";} ?>">

Thanks for your reply. How it can be done, can you please guide?

This simply wouldn't work because this is how your source would look like.

<input type= "text" name ="ch1" disabled='true'
disabled='false'/>

Thanks for your reply. I need to enable a disabled text box as this text box will be disabled by default, so should i write:

<input type= "text" name ="ch1" <?php if(!S_GET['e'] == 3)  {echo "disabled=\"false\"";} ?>">
<input type= "text" name ="ch1" <?php if(!S_GET['e'] == 3)  {echo "disabled=\"disabled\"";} ?>">

If it is disabled by default and on certain condition, you want to enable it, you have to use javascript.

I need to enable it by using php.

If it is disabled by default and on certain condition, you want it to enable it, you have to use javascript.

As far as I know, once you have printed a html element, you can't change it (unless you use javascript). Even almostbob's code decides whether to enable or disable the textbox at runtime.

But the problem with java script is that it can be disabled by the user on browsers. There should be a way to implement it by php.

As far as I know, once you have printed a html element, you can't change it (unless you use javascript). Even almostbob's code decides whether to enable or disable the textbox at runtime.

<offtopic>
Strangely, http://www.w3schools.com/htmldom/prop_text_disabled.asp says textObject.disabled=true|false
But, when I use <input type= "text" id='ch1' name ="ch1" disabled='false' /> it doesn't work.. It still disables the textbox :S
</offtopic>
Anyways, I hope I am wrong and someone else have a way to enable already disabled textbox without using javascript.. :)

Yes I have checked this option also quoted by w3schools, but it is not working. I have searched and some tutorials quoted that "disable" and "readonly" properties can only have one value same like their name:

<input type="text" disabled= "disabled">

<offtopic>
Strangely, http://www.w3schools.com/htmldom/prop_text_disabled.asp says textObject.disabled=true|false
But, when I use <input type= "text" id='ch1' name ="ch1" disabled='false' /> it doesn't work.. It still disables the textbox :S
</offtopic>
Anyways, I hope I am wrong and someone else have a way to enable already disabled textbox without using javascript.. :)

What is the error in this code:

<input type="text" name="ch1" disabled= "true" id="ch1"
<? 
if( $_GET["e"] == 3 || $_GET["e"] == 4) 
 {   
echo "<script>{ document.getElementById('ch1').disabled = false; } </script>";
}
?>  />

It show an extra "/>" in output.

<input type="text" name="ch1" disabled= "true" id="ch1" />
<?
if( $_GET["e"] == 3 || $_GET["e"] == 4) {
echo "<script>document.getElementById('ch1').disabled = ''; </script>";
}
?>

:)

if ($biller_status=='unpaid') {
        echo "<script>{ document.getElementById('checkbox').disabled = false; } </script>";
    }
Member Avatar for diafol

Please consider the fact that this is a dead thread before posting and pushing this to the top of the heap. Thank you.

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.