I am a VB.net programer and I am very new to PHP HTML and Java Scripts

I am doing a project for my company using PHP HTML and Java Scripts and I want to Know how to make readonly a text box after it gets the input

This text box should first get the input and based on that input display other data to the user then it should be read only because it is the key field for the other displayed information

I tried a round with PHP and Javascrpits but could not find a solution

document.getElementById("RunNo").disabled = true;
document.forms["EditRun"]["RunningNo"].disabled="true";
document.getElementById("RunNo").readOnly="readonly";
document.getElementById("RunNo").setAttribute("readonly", "true");
document.getElementById('RunNo').readOnly=true;

the above code do not work
the first 2 works but when the text box is disable the textbox value cannot be used with the remaining code
the lase 3 do not work at all

Please help me:?:

I tried a round with PHP and Javascrpits but could not find a solution

document.getElementById("RunNo").disabled = true;
document.forms["EditRun"]["RunningNo"].disabled="true";
document.getElementById("RunNo").readOnly="readonly";
document.getElementById("RunNo").setAttribute("readonly", "true");
document.getElementById('RunNo').readOnly=true;

The first two look fine, but use true rather than "true" .

document.getElementById("RunNo").disabled = true;
document.forms["EditRun"]["RunningNo"].disabled = true;

... but when the text box is disable the textbox value cannot be used with the remaining code

Disabling the textbox only prevents further user interaction; it should not prevent the remaining code reading (or writing) the textbox's text.

If necessary, you can re-enable the textbox with:

document.getElementById("RunNo").disabled = false;
//or
document.forms["EditRun"]["RunningNo"].disabled = false;

Airshow

Notice: Undefined index: RunningNo in H:\wamp\www\OCBS\includes\form_functions.php on line 15

Notice: Undefined index: RunningNo in H:\wamp\www\OCBS\EditRun.php on line 63

when I put that code the above error messages come where RunningNo is the name of the textbox

I gave you very slightly modified lines of code that you said were working.

If these line(s) were working before, then I can see no reason why, with my suggested mod, they should not be working now.

The error messages suggest that the HTML and javascript are incompatible. ie.

  • document.getElementById("RunNo") doesn't exist, or
  • document.forms["EditRun"] doesn't exist, or
  • document.forms["EditRun"]["RunningNo"] doesn't exist

Has the HTML changed?

Airshow

THE CODE U GAVE WORKS
THE THING IS AFTER THAT CODE WHEN I TRY TO USE THE NAME OF THAT TEXT BOX THE FOLLOWING ERRORS ARE DISPLAYED

Notice: Undefined index: RunningNo in H:\wamp\www\OCBS\includes\form_functions.php on line 15

Notice: Undefined index: RunningNo in H:\wamp\www\OCBS\EditRun.php on line 63

RunningNo is the textbox name
When the textbox is disabled cant we use it's value

Let me run a test .....

... The following code runs successfully in Opera (latest version) and IE9:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>

<script type='text/javascript'>
onload = function(){
	var t1 = document.getElementById("myTextArea");
	var msg = document.getElementById("msg");
	var m = [];
	m.push('1. (from enabled textarea) ' + t1.value);
	t1.disabled = true;
	m.push('2. (from disabled textarea) ' + t1.value);
	msg.innerHTML = m.join("<br/>");
};
</script>
</head>

<body>

<textarea id="myTextArea">This my text</textarea>
<div id="msg"></div>

</body>
</html>

So in both Opera and IE9 (and I expect all other major browsers) it makes no difference to javascript whether a textarea is disabled or not.

Airshow

RunningNo is the textbox name

name, getElementbyID

I Added some PHP code to your code. Now it dispay the error that I am getting

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>

<script type='text/javascript'>
onload = function(){
var t1 = document.getElementById("myTextArea");
var msg = document.getElementById("msg");
var m = [];
m.push('1. (from enabled textarea) ' + t1.value);
t1.disabled = true;
m.push('2. (from disabled textarea) ' + t1.value);
msg.innerHTML = m.join("<br/>");

};
</script>
<?php $username = trim($_POST["myTextArea"])
?>
</head>

<body>

<textarea id="myTextArea">This my text</textarea>
<div id="msg"></div>

</body>
</html>

Please chek it out and let me know

Thanks for all your help.

God bless
eranga

Ok, but that would be a php warning not a javascript error, n'est pas?

In fact I realise now, so were your errors at lines 15 and 63. They have nothing to do with javascript.

You have to learn the difference.

  • PHP runs server-side: by default, PHP errors get reported in the php script's output stream (ie the page),
  • Javascript runs client-side; by default, errors get reported in a popup window (IE) or a javascript console (Opera, Firefox, Chrome).

Remember, this is the Ajax/DHTML/Javascript forum.

For PHP help visit Daniweb's PHP forum.

Airshow

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.