I am trying to create a javascript function where the first argument is a number and the second arg is a string. My code is below, I have added a comments here to make it easier to read.
while ($dbsearch = mysqli_fetch_assoc($run_query)) {
//define 3 vables. Example $dbu = 'Bill.Gates'
//Example $id = 123
// example $func using the values above should say add(123,'Bill.Gates')
$dbu = $dbsearch['Username'];
$id = $dbsearch['PlayerID'];
$func = "add(" . $id . ",'" . $dbu . "')";
//this is a string to output the results of an SQL search. It is working fine. The
// $func is inserted toward the end in the submit button.
echo "<tr><td>" . $id . "</td><td>" . $dbu
. "</td><td><input type='submit' id='PlayerAdded" . $id
. "' value='Add' onclick='" . $func . "'></input></td></tr>";
}
The purpose of the submit button is to add a players name as a registered player in an event.
I have tried changing the $func variable to just output the $id for both arguments and that worked, but I can't get it to output a string (name of person).
How can I fix this please?
Added: Sorry if my question was not clear. I am wanting to know how to get the add function to accept a string as an argument. For example
add(123,'Bill Gates');
$dbsearch['Username']is empty?addfunction are breaking your HTML code, isn't it?\"I would use double quotes for element arrtibutes and use single quotes to place your javascript arguments. Exampleecho "<tr><td>".$id ."</td><td>".$dbu."</td><td><input type=\"submit\" id=\"PlayerAdded".$id."\" value=\"Add\" onclick=\"add('".$id."','".$dbu."');\"></input></td></tr>";