views:

73

answers:

4

Hello,

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?

+4  A: 

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>
greg0ire
can you show me how to do this? sry i'm new in js
matthias
perfect thanks!
matthias
A: 

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>
Matthew Abbott
i have an other input with onload so i don't need a button, but thanks^^
matthias
+1  A: 

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;
dpb
perfect thanks!
matthias
A: 

Why don't you try something in jQuery?

  $("#Anything").click(function() {
     $("#Field1").val($("#Field2").val());
  });

The "click" is just a assumption =)

Kira
i have an onload :-)
matthias
For such a trivial task Jquery is overkill I think!
Tom Gullen