开发者

Access element attribute from request

Is there a way to access an elements attri开发者_如何学Cbutes from a request?

I am receiving a request and I want to access the 'id' attribute of the input tag.

Is this possible?


No, use JavaScript to include element attributes as request data (like querystring or post data) in your request.

<form method="post" action="page.jsp" onsubmit="setDataFirst();">
    <input id="container" name="container" type="hidden" value="" />
    <input id="YourElement" class="AttributeClassValue" name="YourElement" type="text" />
</form>


<script type="text/javascript">
    //This function will execute before the form will be submitted...
    function setDataFirst()
    {
        //Set the value of container to the attribute you want to send to server...
        document.getElementById('container').value = 'YourElementClass=' + document.getElementById('YourElement').attributes('class');
        //After the function execution, the form will be submitted...
    }
</script>


Now in your server you can get the value of POST data `container` which is `YourElementClass=AttributeClassValue`


AFAIK the id attribute is really for CSS styling and Javascript manipulation.

It sounds like you need the id attribute value to be passed back to the server. Whether you are using a POST or GET method, you'll have to use Javascript to manipulate the value of the input field to add the value of the id of the input element to the value of the input element itself.

e.g suppose

`<input type="..." id="fred"  ...`

and the value, on form submission, is 'test' you'll need to write a Javascript function that manipulates the value to 'fred.test'

However, http://www.w3.org/TR/html5-diff/#new-attributes shows the name attribute still in use. If you use

<input type="..." id="fred" name="fred" ...

then you should receive the name/value pair as fred=test, serverside.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜