简体   繁体   中英

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

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;

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>
 document.getElementById('hiddentest').value = document.getElementById('test').value ;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM