• <script type="text/javascript">
    function redirect_to(){
    var pathname = window.location.host;
    var s = document.getElementById('redirect_s').value;
    if(s == "")
    {
    alert('Please Enter the number in textbox');
    }
    else{
    location.replace( "/" + s) ;
    }
    
    }
    </script>
    <form method="post" action="">
    <label class="assistive-text" for="s">Search</label>
    <input id="redirect_s" class="field" type="text" placeholder="Jump to image #" name="redirect_s">
    <input id="searchsubmit" class="submit" type="button" onclick="redirect_to();" value="Search" name="submit">
    </form>

    This bit of code should be directing users to onceuponasidewalk.com/whatevertheyenteredintextbox, but it has decided to instead direct them back to whatever page they started on.

    Any ideas what’s going wrong here?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter JerBurdett

    (@jerburdett)

    I have made some change on your javascript code, please write your script code before end of head tag:

    function redirect_to(){
        var pathname = window.location.host;
        var s = document.getElementById('redirect_s').value;
        if(s == "")
        {
        alert('Please Enter the number in textbox');
        }
        else{
        location.replace( "/" + s) ;
        }
        return false;
      }

    And also made following changes on your html form:
    1. added form action
    2. removed onClick from form button

    Here’s code:

    <form method="post" action="javascript:redirect_to();">
    <label class="assistive-text" for="s">Search</label>
    <input value="3" id="redirect_s" class="field" placeholder="Jump to image #" name="redirect_s" type="text">
    <input id="searchsubmit" class="submit"  value="Search" name="submit" type="submit">
    </form>

    Implement all the above mentioned changes.

    Thread Starter JerBurdett

    (@jerburdett)

    Basically, you rock. I paid some dude on fiverr to write that snippet for me and obviously it didn’t turn out so well.

    This is the code I ended up with, in case someone else want to have a jump to page text box:

    <script type="text/javascript">
    function redirect_to(){
    var pathname = window.location.host;
    var s = document.getElementById('redirect_s').value;
    if(s == "")
    {
    alert('Please Enter the number in textbox');
    }
    else{
    location.replace( "/" + s) ;
    }
    
    }
    </script>
    <form method="post" action="javascript:redirect_to();">
    <label class="assistive-text" for="s">Search</label>
    <input value="" id="redirect_s" class="field" placeholder="Jump to image #" name="redirect_s" type="text">
    <input id="searchsubmit" class="submit"  value="Search" name="submit" type="submit">
    </form>

    Thanks again, Chandan!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Javascript being naughty’ is closed to new replies.