最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

html - passing var to url when click button via javascript - Stack Overflow

programmeradmin3浏览0评论
<input type="text" name="my_sld" style="width: 55%" value="">
<br />
<select name="my_tld" style="width: 20%">
    <option value="" label="">  </option>
    <option value="net" label="net">  </option>
    <option value="org" label="org">  </option>
</select>

<script>
var sld = my_sld();
var tld = my_tld();
var domain = sld + tld;
</script>

<button go to = / + domain + >

how to make my_sld + my_tld go to mysite when i click the button via javascript?

for example =

<input type="text" name="my_sld" style="width: 55%" value="">
<br />
<select name="my_tld" style="width: 20%">
    <option value="" label=""> . </option>
    <option value="net" label="net">  </option>
    <option value="org" label="org">  </option>
</select>

<script>
var sld = my_sld();
var tld = my_tld();
var domain = sld + tld;
</script>

<button go to = http://example./check/ + domain + >

how to make my_sld + my_tld go to mysite when i click the button via javascript?

for example = http://example./check?domain=thedomainname

Share Improve this question edited Nov 19, 2015 at 20:09 Petr Felzmann 1,3134 gold badges20 silver badges39 bronze badges asked Nov 19, 2015 at 19:37 Selakarweb di siniSelakarweb di sini 111 silver badge3 bronze badges 2
  • Try looking into window.location. You may have to have your button call a javascript function through onclick, which then sets the location. – Nate Young Commented Nov 19, 2015 at 19:41
  • Give to the input text and to the select an id attribute then load the value with jquery. You can append that value to the url – Antonio Commented Nov 19, 2015 at 19:44
Add a ment  | 

2 Answers 2

Reset to default 7

You should do like this..

First provide any ID to button :

<button id=“test” value=“click">

Then in javascript you should do like:

<script>
$("#test").click(function(){
      var sld = my_sld();
      var tld = my_tld();
      var domain = sld+tld;
      window.location.href="http://example./check?domain="+domain;
 })
</script>
<script>
function redirect() {
    window.location = 'http://example./check/' + sld + tld;
}
</script>
<button onclick='redirect();'>

or with unobtrusive and still pure javascript

<button id='redirect'>
<script>
    document.getElementById('redirect').onclick = function() {
        window.location = 'http://example./check/' + sld + tld;
    };
</script>
发布评论

评论列表(0)

  1. 暂无评论