how can i transfer the Value from Input 1 in 2 and add some letters?
<script type="text/javascript">
function doit(){
document.getElementById('input2').value=document.getElementById('input1').value;
}
</script>
Input1: 2342
Input2: pcid2342d
Can some one help me?
how can i transfer the Value from Input 1 in 2 and add some letters?
<script type="text/javascript">
function doit(){
document.getElementById('input2').value=document.getElementById('input1').value;
}
</script>
Input1: 2342
Input2: pcid2342d
Can some one help me?
Share Improve this question edited Jul 1, 2010 at 13:23 gblazex 50.1k12 gold badges99 silver badges92 bronze badges asked Jul 1, 2010 at 13:18 SebastianSebastian 5146 gold badges18 silver badges34 bronze badges 3- Your attempt looks good. Does it not work? – Gumbo Commented Jul 1, 2010 at 13:20
- The code appears to be mostly correct. What errors are you getting? What is not working? – Oded Commented Jul 1, 2010 at 13:21
- there are no errors, it was that i don't know how to add letters on the string :-) – Sebastian Commented Jul 1, 2010 at 13:32
4 Answers
Reset to default 7Just use the + operator to add a string before and after the input value.
<script type="text/javascript">
function doit(){
document.getElementById('input2').value="pcid" + document.getElementById('input1').value + "d";
}
</script>
String concatenation:
document.getElementById('input2').value = "stuff" + document.getElementById('input1').value + "other stuff";
When dealing with numbers you could start by concatenating with empty string to avoid adding numbers together instead of concatenating to strings (because of operator evaluation order):
document.getElementById('input2').value = "" + 1234 + 567 + document.getElementById('input1').value + 89;
Well you seem to have done the work already, all you need is something to click on to execute it:
<button onclick="doit()">click me</button>
Why don't you try something in jQuery?
$("#Anything").click(function() {
$("#Field1").val($("#Field2").val());
});
The "click" is just a assumption =)