简体   繁体   中英

How to submit disabled element's value in JS

In order to submit the disabled elements in JS I found this method of using a hidden element. However, due to lack of knowledge of web languages I am unable to make it work and therefore I would like to know the code for following:

  • Defining a hidden element(variable) in HTML.
  • Updating the element in JS.
  • Using the element(variable) in CGI.

check the DOMDocument

What have you tried for yourself so far?

What you are asking is kind of broad and, well, pretty basic stuff. Anyway, something like this should do it:

Define the hidden element:

<input type="hidden" name="foo" id="foo" />

Update the element using JavaScript:

var el = document.getElementById('foo');
el.value = 'bar';

Use the element in your server-side code depends heavily on your choice of platform. I'll leave that one up to you, but you should know that sending the element to the server using a POST or GET request should make it accessible to whatever language it is you are using.

IE, using JavaScript to send the data to the server and PHP to read it out:

JavaScript:

// assuming you have a form with id="myForm"
var form = document.getElementById('myForm');
form.submit();

PHP:

echo $_POST['foo']; // should return bar   

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM