I have been racking my brain around this for a few hours. Basically I have a div that displays user info from a database:
if (isset($_SESSION['email']) && ($_SESSION['userID'])) {
$sql = "SELECT * FROM user_accounts WHERE email='" . $_SESSION['email'] . "' AND user_id=" . $_SESSION['userID'] ;
$userRecordSet = $_dbConn->query($sql);
if ($userRecordSet != NULL) {
$userRow = $userRecordSet->getrow();
$firstName = $userRow['first_name'];
$lastName = $userRow['last_name'];
}
}
The first and last name are then placed into the div and displayed to the user.
<div id="nameChange" title="Click to edit"><?=$firstName?> <?=$lastName?></div>
when the user clicks on this DIV element it converts into a text box, and displays the contents of the user’s first and last name taken from the DIV. here is the Jquery to support the above.
//execute when nameChange DIV is clicked
$("#nameChange").click(function(){
//check if there are any existing input elements
if ($(this).children('input').length == 0){
$("#save").css("display", "inline");
//variable that contains input HTML to replace
var inputbox = "<input type='text' class='inputbox' name='userName' value=\""+$(this).text()+"\">";
//insert the HTML intp the div
$(this).html(inputbox);
//automatically give focus to the input box
$("this .inputbox").focus();
}
});
Doing this creates an issue with the database because I want the first and last name to go into separate columns but after it is converted into a text box, the contents are placed into a single variable. now for the question.
how can I parse through the text box and assign 2 separate variables for the first and last name?
This assumes that your final parsing to the database is done with
php.here are two function I use to get the first and last name form a text input:
This takes into account people that have two first names such as ” mary lynn”