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

javascript - create dynamic link based on text input field - Stack Overflow

programmeradmin8浏览0评论

I'm trying to make a text input field where visitors can enter a value and then hit go or submit.

Based on the digit number they would be send to a new page.

For example if they enter 123 and hit submit it would send them to

Could anybody please help me get this up and running? Thank you

I'm trying to make a text input field where visitors can enter a value and then hit go or submit.

Based on the digit number they would be send to a new page.

For example if they enter 123 and hit submit it would send them to http://www.example.com/page/123

Could anybody please help me get this up and running? Thank you

Share Improve this question edited Jun 17, 2014 at 14:37 Mihai Iorga 39.7k17 gold badges108 silver badges109 bronze badges asked Jun 17, 2014 at 14:17 Reza AbbasianReza Abbasian 431 gold badge1 silver badge5 bronze badges 6
  • 5 Show us what you tried so far. – h.s.o.b.s Commented Jun 17, 2014 at 14:19
  • what language are you using? what server? – Zardaloop Commented Jun 17, 2014 at 14:20
  • If you haven't implement anything I would suggest using bottle in python – Zardaloop Commented Jun 17, 2014 at 14:21
  • @rm-rf <input type="text" value="11" id="input"> <a href="example.com/page" id="link">Linked text</a> <script> var input = document.getElementById('input'); link = document.getElementById('link'), link.onclick = link.oncontextmenu = link.onmousedown = function () { this.href = ('example.com/page/")+.input.value; }; </script> – Reza Abbasian Commented Jun 17, 2014 at 14:22
  • @FarzanMajdani javascript or php – Reza Abbasian Commented Jun 17, 2014 at 14:23
 |  Show 1 more comment

1 Answer 1

Reset to default 15

Here we go have fun. just copy the code and save it as html. you don't need php or such. it is way too simple to need a server side code.

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>Untitled Page</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.11.0.min.js"></script>

<script type="text/javascript">

$(document).ready(function(){

    $('#button').click(function(e) {  
        var inputvalue = $("#input").val();
        window.location.replace(" http://www.example.com/page/"+inputvalue);

    });
});
</script> 
</head>
<body>

       <input type="text" value="11" id="input"> 
       <button type="button" id="button">Click Me!</button>
</body>
</html>
发布评论

评论列表(0)

  1. 暂无评论