Hi,

I need to discuss some problems regarding handling of text boxes using php which are as follows:

  1. Can we set focus of a text box when an if condition is true in php?
  2. Can we disable a text box when an if condition is true in php? I need to disable and enable the text box based on some true and false conditions.

Thanks.
Regards,

Recommended Answers

All 6 Replies

Answer is Yes to both the questions.

<html>
<body>
<form name='test' method='post'>
<input type='text' id='name' name='name'>
<input type='text' id='age' name='age'>
</form>
<?php
 $value = 1;
 if($value == 1) {
 	echo "<script>document.getElementById('age').focus();</script>";
 	echo "<script>document.getElementById('name').disabled=true;</script></script>";
 }
?>
</body>
</html>

Thanks for your reply. But if I dont want to use java script then how it can be possible?

Umm.. I am not sure actually! :-/

It's ok. Thanks for your time. The problem is resolved. It will be:

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

*Bangs head*You are right..
But what about focus() ?

I didnot searched it's solution yet.

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.