Forum Moderators: open

Message Too Old, No Replies

changing the text field to label

important

         

ksvijay

6:58 am on May 24, 2005 (gmt 0)

10+ Year Member



<form name="textTest">
<input type="text" name="text1" onBlur="populateSecond(this)">
<input type="text" name="text2">
</form>

function populateSecond(form)
{
document.forms[0].elements['text2'].value=form.value;
}

------------------------------------------------------
After the second textfield is populated with values it should become a label, so that anybody cannot edit it,

How can i do that through javascript, if anybody knows pls reply to it

tahnk u

birdbrain

11:08 am on May 24, 2005 (gmt 0)



Hi there ksvijay,

try this...



<script type="text/javascript">
<!--
function populateSecond(form) {

var input=document.forms[0][1];

if(input.readOnly==true) {
input.style.color="#fff";
input.style.backgroundColor="#000";
return;
}
else {
input.value=form.value;
input.readOnly="readonly"
}
}
//-->
</script>

<form action="#">
<div>
<input type="text" name="text1" onblur="populateSecond(this)">
<input type="text" name="text2">
</div>
</form>


birdbrain

ksvijay

11:19 am on May 24, 2005 (gmt 0)

10+ Year Member



Thanks 4 the reply, after the text field is changed to label , again i focus the cursor to the first textfield and i teke the cursor out of it , it is giving error "document.forms.0.elements.text2 is null or not an object" and "readonly is null or not an object" .
Here is the full verson of that code>

<!doctype html public "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title> New Document </title>
<meta name="Generator" content="EditPlus">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
</head>
<script>
<!--
function populateSecond(form)
{
var input=document.forms[0][1];
if(input.readOnly==true) {
input.style.color="#fff";
input.style.backgroundColor="#000";
return;
}
else {
input.value=form.value;
input.readOnly="readonly"
}

test.innerHTML=document.textTest.text2.value;
}

-->
</script>
<body>
<form name="textTest">

<input type="text" name="text1" onBlur="populateSecond(this)" >
<div class= "division" id="test"><input type="text" name="text2"></div>
</form>
</body>
</html>

birdbrain

12:38 pm on May 24, 2005 (gmt 0)



Hi there ksvijay,


after the text field is changed to label , again I focus the cursor to the first textfield
and I take the cursor out of it , it is giving error...

"document.forms.0.elements.text2 is null or not an object" and "readonly is null or not an object"

The reason for this is this line that you have inserted into the code....


test.innerHTML=document.textTest.text2.value;

...which, of course, removes the 'text2' input. ;)

So try it like this...


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/1999/REC-html401-19991224">
<html>
<head>
<title> New Document </title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<meta name="Generator" content="EditPlus">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
<script type="text/javascript">
<!--
function populateSecond(form) {
var input=document.forms[0][1];
if(input.readOnly==true) {
return;
}
else {
input.value=form.value;
input.readOnly="readonly"
input.style.fontWeight="bold";
input.style.border="0px solid #000";
}
}
//-->
</script>
</head>
<body>
<form action="#" name="textTest">
<div>
<input type="text" name="text1" onBlur="populateSecond(this)">
</div>
<div class="division" id="test">
<input type="text" name="text2"></div>
</form>
</body>

...instead of removing the input, I have removed the border and made the text bold.

birdbrain

ksvijay

12:55 pm on May 24, 2005 (gmt 0)

10+ Year Member



Now it is working fine
thanks birdbrain