Wednesday, 14 October 2015

Need to take two text field values and add together to another field

For PHP (on the server side):
$ScreenName = $_POST["first_name"]." ".$_POST["last_name"]
With jQuery (on the client side) you'll have to add ids to the fields to easier access them:

<p>First Name <input type="text" name="first_name" id="first_name"> Last Name <input type="text" name="last_name" id="last_name"></p>
<input type="hidden" name="screen_name" value="first_name + last_name" id="screen_name">

And then on the form submit event (or input field change event) set the screen_name field value:

var screenNameVal = $.("#first_name").attr("value")+" "+$.("#last_name").attr("value");
$.("#screen_name").attr("value",screenNameVal);

No comments:

Post a Comment