-3

HTML

<p id="a" name="a"></p>

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.

  • 1
    You asked an extremely similar question 25 minutes ago, and I told you what you would need to do: [Your Question](http://stackoverflow.com/questions/16155008/i-need-to-echo-results-that-are-rendered-inside-a-span-tag) – Unexpected Pair of Colons Apr 22 '13 at 19:45

2 Answers2

3

That's not how forms work.

The browser will only send values of form controls (<input>, <select>, <textarea>) to the server.
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.

nickb
  • 59,313
  • 13
  • 108
  • 143
SLaks
  • 868,454
  • 176
  • 1,908
  • 1,964
0

I guess, you want only to change the values in HTML elements. For that you need a XML parser (i.d). I think shamittimar's post may help you. He does exactly what you want.

Community
  • 1
  • 1
Matt3o12
  • 4,192
  • 6
  • 32
  • 47