Avatar of justmelat
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 undefined
Last Comment

8/22/2022 - Mon
Roger Baklund

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question

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


perfecto!!! thank you.
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck