Raja D
Raja D

Reputation:

How to assign value of textbox to another textbox in html?

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..

Upvotes: 0

Views: 35136

Answers (3)

Sonny Boy
Sonny Boy

Reputation: 8016

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>

Upvotes: 3

3Dave
3Dave

Reputation: 29041

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;

Upvotes: 7

gn22
gn22

Reputation: 2086

 document.getElementById('hiddentest').value = document.getElementById('test').value ;

Upvotes: 1

Related Questions