Forum Moderators: open
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
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
<!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>
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