954,585 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Text Enable/Disable

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' ";
?>
/>
marjan_m
Junior Poster
149 posts since Apr 2005
Reputation Points: 21
Solved Threads: 0
 

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

<input type= "text" name ="ch1" disabled='true'
disabled='false'/>
nav33n
Purple hazed!
Moderator
4,465 posts since Nov 2007
Reputation Points: 524
Solved Threads: 356
 
<input type= "text" name ="ch1" <?php if(!S_GET['e'] == 3)  {echo "disabled=\"disabled\"";} ?>">
almostbob
Posting Sensei
3,149 posts since Jan 2009
Reputation Points: 571
Solved Threads: 376
 

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'/>
marjan_m
Junior Poster
149 posts since Apr 2005
Reputation Points: 21
Solved Threads: 0
 

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\"";} ?>">
marjan_m
Junior Poster
149 posts since Apr 2005
Reputation Points: 21
Solved Threads: 0
 

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

nav33n
Purple hazed!
Moderator
4,465 posts since Nov 2007
Reputation Points: 524
Solved Threads: 356
 

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.
marjan_m
Junior Poster
149 posts since Apr 2005
Reputation Points: 21
Solved Threads: 0
 

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.

nav33n
Purple hazed!
Moderator
4,465 posts since Nov 2007
Reputation Points: 524
Solved Threads: 356
 

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.
marjan_m
Junior Poster
149 posts since Apr 2005
Reputation Points: 21
Solved Threads: 0
 


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

Anyways, I hope I am wrong and someone else have a way to enable already disabled textbox without using javascript.. :)

nav33n
Purple hazed!
Moderator
4,465 posts since Nov 2007
Reputation Points: 524
Solved Threads: 356
 

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">
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 Anyways, I hope I am wrong and someone else have a way to enable already disabled textbox without using javascript.. :)
marjan_m
Junior Poster
149 posts since Apr 2005
Reputation Points: 21
Solved Threads: 0
 

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.

marjan_m
Junior Poster
149 posts since Apr 2005
Reputation Points: 21
Solved Threads: 0
 
<input type="text" name="ch1" disabled= "true" id="ch1" />
<?
if( $_GET["e"] == 3 || $_GET["e"] == 4) {
echo "<script>document.getElementById('ch1').disabled = ''; </script>";
}
?>

:)

nav33n
Purple hazed!
Moderator
4,465 posts since Nov 2007
Reputation Points: 524
Solved Threads: 356
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You