Link to home
Start Free TrialLog in
Avatar of justmelat

asked on

How do I concatenate two textbox values into one variable in my php/javascript code?

I have the two fields shown belown; in my javascript, I want the BJ variable to hold both the Q_28 and Q_26 values.  I tried to concatenate them, but it doesn't work.  Could someone show me how to do this please?
<input id="text8" type="hidden" name="text8" value="<?php echo $_REQUEST['Q_28'];?>">
<input id="text4" type="hidden" name="text4" value="<?php echo $_REQUEST['Q_26'];?>">
var BJ. = document.getElementById('text8').value; //Project Title
   var BJ. = document.getElementById('text4').value; //Project type

Open in new window

Avatar of Roger Baklund
Roger Baklund
Flag of Norway image

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of hielo
the .= operator exists in php, not in javascript. In javascript you need to use +=. Also you need to use var only once - when you are declaring the variable:

var BJ = document.getElementById('text8').value; //Project Title
BJ  += '  ' + document.getElementById('text4').value; //Project type
Avatar of justmelat



perfecto!!! thank you.