24287

How can i define a PHP variable by the content of an HTML tag? [closed]

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.

Answer2:

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.

Recommend

  • Variable concatenated mysql query string runs fine in phpMyAdmin but not PHP in script
  • How to query an input in Python without outputting a new line
  • PHP Profiles using template of /profile/name
  • Yii: any way to save the images in compressed form?
  • How can you tell if a Python program has anything to read from stdin?
  • wxWidgets: Detecting click event on custom controls
  • How to limit cursor movement in WPF based app?
  • Sum and Average of a series of numbers inputed to a text field
  • Spring MVC redirect with custom http headers
  • Encode string to match encoded form field name in PHP POST array
  • Passing parameter through “window.location.href”
  • Create a multiple screen android application
  • array_search() in Session Array
  • Why does the following throw an “Object doesn't support property or method 'importNode
  • Microsoft Excel Pivot miscalculation in Sum for positive and negative numbers
  • Why must we declare a variable name when adding a method to a struct in Golang?
  • what makes a request a new request in asp.net C#
  • how to upload multiple files in c# windows application
  • System.InvalidCastException: Specified cast is not valid
  • How to handle images sent by a mobile device?
  • Rails Find when some params will be blank
  • Read a local file using javascript
  • Apache 2.4 and php-fpm does not trigger apache http basic auth for php pages
  • Updating server-side rendering client-side
  • Upload files with Ajax and Jquery
  • Adding custom controls to a full screen movie
  • jQuery tmpl and DataLink beta
  • Do I've to free mysql result after storing it?
  • R: gsub and capture
  • jqPlot EnhancedLegendRenderer plugin does not toggle series for Pie charts
  • Comma separated Values
  • A cron job substitute?
  • json Serialization in asp
  • SQL merge duplicate rows and join values that are different
  • Proper way to use connect-multiparty with express.js?
  • How to set the response of a form post action to a iframe source?
  • Change div Background jquery
  • Qt: Run a script BEFORE make
  • reshape alternating columns in less time and using less memory
  • How to load view controller without button in storyboard?