How to use a php variable inside a form which is a value of innerHTML?

Erlisar Vasquez

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 ?

Ajith

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.

edited at
0

Comments

0 comments
Login to comment

Related

How to use a PHP variable which is obtained after a loop in HTML value?

How to use a variable which is inside a (def) function?

How to insert python variable inside the value of a form?

How can I use a variable with a value which is declared inside a function, in javascript?

How can i use the value which i got from a form as an variable in my dao class?

How to use php variable inside another one

PHP/MYSQLI how can I return a variable from a while loop inside a form to use in a $_GET request in that form's action/method?

How to put php variable inside php variable with a javascript value

How to return a variable's value which is declared inside of a Promise

How to put variable inside a innerHTML tag in javascript?

How to set value of a form control which is inside a form array in Angular reactive form

Is it possible to use <input> tags inside a php function which is then inside <form> tags?

How to get variable which is not defined in the form using php?

How to use innerHTML and ejs together inside for loop?

How to use php variable inside a javascript code in a php code?

How to use $ regex value as a php variable?

How to use PHP variable value in javascript?

How define variable with value inside Class and how to use in other Class

How to add PHP code inside input's value in a form

How to use variable, which value should be set in keyword or test, in XPATH?

How to use a php variable outside loop which is defined in foreach loop

how to use value of a variable that was calculated inside a loop in java

How to use a variable inside a function which is defined (variable) in some other function within a class in python?

How to use the jquery variable in script inside the PHP tag echo?

How to use an external variable inside a class/function/object in php

How to use php variable inside pdf ->page_script()?

How to use jquery variable in php same page without submitted the form

How to change value of select input which is inside a form balise (ant design)

Change variable value inside a variable in PHP

TOP Ranking

HotTag

Archive