views:

259

answers:

3

Hi All :
I want to assign value of text box in another text box's value present in the immediate next line. How to do that using html and javascript?.

Eg:
input type = "text" name = "test" value = "pass">
input type = "hidden" name = "hiddentest" value = "(here i have to get the value of previous textbox)"/>

Please help me..

+1  A: 
 document.getElementById('hiddentest').value = document.getElementById('test').value ;
Gurdas Nijor
+5  A: 

Assuming the two textboxes have IDs of "textbox1" and "textbox2", respectively:

var tb1 = document.getElementById('textbox1');
var tb2 = document.getElementById('textbox2');

tb1.value=tb2.value;
David Lively
A: 

First, put a function into your page that will handle it:

<script language="JavaScript" type="text/javascript">
function setHiddenValue()
{
  document.getElementById('txtHidden').value = document.getElementById('txtVisible').value;
}
</script>

Next, hookup the event on the visible textbox to call the function whenever the text changes:

<input type="text" onChange="javascript:setHiddenValue();"></input>
Sonny Boy
I am not gonna change anything. During the page load itself, it has assign the value to hiddeb dield. How to do that??
To do it during the page load, just add the following attribute to your body tag: onLoad="javascript:setHiddenValue();"
Sonny Boy
Get rid of the "javascript:" sillyness. In context it just labels a loop that isn't there. It *doesn't* say "this is JS" for that you use http://www.w3.org/TR/html4/interact/scripts.html#h-18.2.2.1
David Dorward