Reputation: 514
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?
Upvotes: 4
Views: 21436
Reputation:
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;
Upvotes: 1
Reputation: 628
Why don't you try something in jQuery?
$("#Anything").click(function() {
$("#Field1").val($("#Field2").val());
});
The "click" is just a assumption =)
Upvotes: 0
Reputation: 61599
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>
Upvotes: 0
Reputation: 23265
Just 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>
Upvotes: 7