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:
- D开发者_JAVA技巧efining a hidden element(variable) in HTML.
- Updating the element in JS.
- Using the element(variable) in CGI.
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
check the DOMDocument
精彩评论