1

I'm tend to make a input field and a button that works on mobile browser. When I input 123 on the field and click the button, it should go to http://example.com/123.html

Then I combine this two thread 24266205 and 22015908 together. Making the code below:

<script type="text/javascript">
$(document).ready(function(){
    $('#button').on('click touchstart', function(e) {  
        var inputvalue = $("#input").val();
        window.location.replace(" http://www.example.com/page/"+inputvalue);
    });
});

But when I put it on test, it can be pressed down. But it can't forward me to the page I want.

It does work on Windows, but not on any mobiles. Is there something wrong with the codes?

dozilla
  • 13
  • 2

2 Answers2

0

Use window.location instead of window.location.replace as,

window.location = "http://www.example.com/page/"+inputvalue;
kmg
  • 499
  • 3
  • 16
0

Try the following

<!doctype html>
<input id=input>
<a href="" id=button>link</a>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.js">
</script>
<script>
$(document).ready(function(){
    $('#button').on('click', function(e) {  
        var inputvalue = $("#input").val();
        window.location.replace(" http://www.example.com/page/"+inputvalue);
        return false;
    });
});

</script>
Lime
  • 13,400
  • 11
  • 56
  • 88