What I want to happen is to display a name. If the user clicks the edit button, a form will appear with with still the name in it.
function edit(firstname){
document.getElementById("firstname-div").innerHTML='<input type="text" name="firstname" value=firstname>';
}
First name:<div id="firstname-div"><?php echo $firstname ?></div>
<button type="button" onclick="edit('<?php $firstname ?>')">edit</button><br>
I know it has something to do with value=firstname
. What will be the variable? Is it gonna be firstname
?
You're missing "Echo" In your HTMl Code. If you want to use php variable value in client side you need to echo that value
Updated HTML
First name:<div id="firstname-div"><?php echo $firstname ?></div>
<button type="button" onclick="edit('<?php echo $firstname ?>')">edit</button><br>
Javascript: You need to Use Javascript Concatenation Operator
function edit(firstname){
document.getElementById("firstname-div").innerHTML='<input type="text" name="firstname" value="'+firstname+'">';
}
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments