admin管理员组文章数量:1236560
Can I get the value of a text field in html without a form and without submit?
I currently have a form on my website and inside this form I have a textfield. Unfortunately I can't have 2 forms at the same time (but I actually need two seperate actions), so I am looking for a way to get the value of the textfield without a submit.
All help is appreciated!
Can I get the value of a text field in html without a form and without submit?
I currently have a form on my website and inside this form I have a textfield. Unfortunately I can't have 2 forms at the same time (but I actually need two seperate actions), so I am looking for a way to get the value of the textfield without a submit.
All help is appreciated!
Share Improve this question asked Dec 6, 2011 at 8:33 nimrodnimrod 5,73230 gold badges88 silver badges152 bronze badges4 Answers
Reset to default 12Try document.getElementById("textfield-id").value
You can get a reference to the text field element (via getElementById
or any of several other DOM mechanisms), and then look at its value
property.
Separately, if your form
element has a name
, and your input element has a name, you can access them via window
: window.formName.textFieldName.value
I don't think this is covered by an active spec (yet), but it probably will be at some stage (probably by an evolution of this draft spec or a replacement of it) as it's nearly universally supported.
References:
- DOM2 Core
- DOM2 HTML Bindings
- DOM3 Core
- HTML5 APIs
Alternately:
...I can't have 2 forms at the same time (but I actually need two seperate actions).
You can have two submit buttons with the same name but different values, and differentiate between which one was clicked on the server (the value for the one that was clicked will be sent). So if you have two submits called "command" and one has the value "Foo" and the other "Bar", clicking the "Foo" button sends command=Foo
to the server along with the various form fields, whereas clicking the "Bar" button sends command=Bar
to the server with the other fields.
Maybe you can use this jQuery / AJAX to submit the form without refreshing te page?
http://net.tutsplus.com/tutorials/javascript-ajax/submit-a-form-without-page-refresh-using-jquery/
else you can use javascript:
document.getElementById('id').value
document.getElementById('my_txt_box_id').value
where your text box 's id is "my_txt_box_id"
Does that fit your need ?
本文标签: javascriptGet textfield value without submit (html)Stack Overflow
版权声明:本文标题:javascript - Get textfield value without submit (html) - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1739494465a2165754.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论