Skip to content Skip to sidebar Skip to footer

Concatenation Of An Input Value And String Variable

I am trying to concatenate the value of the input with the String variable. For instance: (lets say that the input with an id 'input1' has the value of 'tttttt') var test = 'blabla

Solution 1:

Try

<input type="text" name="text" id="input1" value="ttttttt"/>

JS

<script>
$(document).ready(function(){
    var test = 'blabla' + $('#input1').val() + 'blabla';
    alert(test);
});
</script>

Solution 2:

What it seems to me is that either you are missing a jQuery library at the top or this script is not called in the doc ready handler:

<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script>
   $(function () {
      var test = 'blabla' + $('#input1').val() + 'blabla';
      alert(test);
   });
</script>

Demo Fiddle

Be sure that your #input1 has a value contained in.


Post a Comment for "Concatenation Of An Input Value And String Variable"