![How can i define a PHP variable by the content of an HTML tag? [closed]](https://www.xszz.org/skin/wt/rpic/t14.jpg)
Question:
HTML
<p id="a" name="a">
Javascript
document.getElementById("a").innerHTML=price;
If price is a variable how do I make a php variable that is = to the result that is placed in the HTML of id "a" i?
$price = $_POST['a'];
when echoed this variable comes up blank, and yes I do have a form set up that is handled by a PHP page.
Answer1:That's not how forms work.
The browser will only send values of <strong>form controls</strong> (<input>
, <select>
, <textarea>
) to the server.<br />
It won't send values of arbitrary named elements. (in fact, that name="a"
is invalid HTML)
Instead, you should use an <input type="hidden" name="a" value="" />
, and set the value
attribute of this <input>
tag to the value you want PHP to get.
I guess, you want only to change the values in HTML elements. For that you need a XML parser (<a href="http://www.php.net/manual/en/book.xml.php" rel="nofollow">i.d</a>). I think <a href="https://stackoverflow.com/a/3627553/1493365" rel="nofollow">shamittimar's post</a> may help you. He does exactly what you want.