admin 管理员组文章数量: 1086019
I have to link three input values to the link. How I can do in easy way and I click the link I want open the URL.
<html>
<script type="text/javascript">
function changeText2(){
var userInput0 = document.getElementById('userInput').value;
var userInput11 = document.getElementById('userInput').value;
var userInput21 = document.getElementById('userInput2').value;
document.write("userinput");
}
</script>
Here is a link : <a href="/00ON0000000FOHS?pc0=userInput0&pn0=userInput11&pv0=userInput21" >nothing here yet</a> <br/>
<input type='text' id='userInput' value='Enter Search String Here' />
<input type='text' id='userInput1' value='Enter Text Here' />
<input type='text' id='userInput2' value='Enter Text Here' />
<input type='button' onclick='changeText2()' value='Change Link'/>
</html>
I have to link three input values to the link. How I can do in easy way and I click the link I want open the URL.
<html>
<script type="text/javascript">
function changeText2(){
var userInput0 = document.getElementById('userInput').value;
var userInput11 = document.getElementById('userInput').value;
var userInput21 = document.getElementById('userInput2').value;
document.write("userinput");
}
</script>
Here is a link : <a href="/00ON0000000FOHS?pc0=userInput0&pn0=userInput11&pv0=userInput21" >nothing here yet</a> <br/>
<input type='text' id='userInput' value='Enter Search String Here' />
<input type='text' id='userInput1' value='Enter Text Here' />
<input type='text' id='userInput2' value='Enter Text Here' />
<input type='button' onclick='changeText2()' value='Change Link'/>
</html>
Share
Improve this question
edited Dec 16, 2013 at 10:40
Mr. Polywhirl
48.9k12 gold badges93 silver badges144 bronze badges
asked Dec 16, 2013 at 10:33
tejdeeptejdeep
1151 silver badge11 bronze badges
5
- 1 your question is not clear.. – Kamlesh Meghwal Commented Dec 16, 2013 at 10:34
- Do you want to make new link? or just need to create parameters for query string from the inputs? It seems that you want to add parameters ! – Dhaval Marthak Commented Dec 16, 2013 at 10:36
- Use form tag and set this href value to action. and method as Get, and in the hyper link set href as # and on click of hyperlink call form. submit() – Priyank Commented Dec 16, 2013 at 10:37
- i am getting three inputs from the user and that three data to be inserted in the url ""/00ON0000000FOHS?pc0=**userInput0&pn0=**userInput11**&pv0=**userInput21"" and clicking the button .the url has to opened. – tejdeep Commented Dec 16, 2013 at 10:39
- Just use a form and a submit button. – Quentin Commented Dec 16, 2013 at 10:41
4 Answers
Reset to default 3If Your link is static than you can create your href link in script it self like :
var link = document.getElementById("test");
link.href = "/00ON0000000FOHS?pc0="+userInput0+"pn0="+userInput11+"pv0="+userInput21;
Here test
is id of your <a>
element.
You can crate href link by appending parameter value.
I wrote a jsFiddle with a working solution:
http://jsfiddle/t8kAS/
Note that I removed the Button and put the event on the onchange event.
$(".jsCustomField").on("change", function() {
var customLink = linkTemplate.replace("{0}", $input1.val())
.replace("{1}", $input2.val())
.replace("{2}", $input3.val());
$dynLink.attr("href", customLink);
});
Hope this helps!
The most standard-based way is using form with GET method
<form method='GET' action='/00ON0000000FOHS?'>
<input type='text' id='userInput' name='pc0' value='Enter Search String Here' />
<input type='text' id='userInput1' name=pn0' value='Enter Text Here' />
<input type='text' id='userInput2' name='pv0' value='Enter Text Here' />
<input type='submit' value='Change Link'/>
</form>
The name part of the input tag will be used as the argument key, and the value entered into the input field is the value in the get request.
Change your function to:
function changeText2(){
var userInput0 = document.getElementById('userInput').value;
var userInput11 = document.getElementById('userInput1').value;
var userInput21 = document.getElementById('userInput2').value;
//document.write("userinput");
window.open("/00ON0000000FOHS?pc0="+userInput0+"&pn0="+userInput11+"&pv0="+userInput21, "_self");
}
If you want it to open in a new window, use "_blank" in the 2nd argument of window.open.
After reading STO's answer (it's inaccurate) I realize, you actually don't need to use js for this. The standard html form was built for exactly this. Use just this, no js required:
<form method='GET' action='/00ON0000000FOHS'>
<input type='text' id='userInput' name='pc0' value='Enter Search String Here' />
<input type='text' id='userInput1' name='pn0' value='Enter Text Here' />
<input type='text' id='userInput2' name='pv0' value='Enter Text Here' />
<input type='submit' value='Change Link'/>
</form>
The name part of the input tag will be used as the argument key, and the value entered into the input field is the value in the get request.
本文标签: javascriptI want to insert input values to linkStack Overflow
版权声明:本文标题:javascript - I want to insert input values to link - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.roclinux.cn/p/1744025556a2520570.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论