Title: Javascript being naughty
Last modified: August 20, 2016

---

# Javascript being naughty

 *  [JerBurdett](https://wordpress.org/support/users/jerburdett/)
 * (@jerburdett)
 * [13 years, 9 months ago](https://wordpress.org/support/topic/javascript-being-naughty/)
 *     ```
       <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](https://wordpress.org/support/users/jerburdett/)
 * (@jerburdett)
 * [13 years, 9 months ago](https://wordpress.org/support/topic/javascript-being-naughty/#post-2971946)
 * Oh, also: [http://www.onceuponasidewalk.com](http://www.onceuponasidewalk.com)
 *  [Chandan Kumar](https://wordpress.org/support/users/chandanonline4u/)
 * (@chandanonline4u)
 * [13 years, 9 months ago](https://wordpress.org/support/topic/javascript-being-naughty/#post-2971983)
 * 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](https://wordpress.org/support/users/jerburdett/)
 * (@jerburdett)
 * [13 years, 9 months ago](https://wordpress.org/support/topic/javascript-being-naughty/#post-2971988)
 * 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.

## Tags

 * [code](https://wordpress.org/support/topic-tag/code/)
 * [java](https://wordpress.org/support/topic-tag/java/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 3 replies
 * 2 participants
 * Last reply from: [JerBurdett](https://wordpress.org/support/users/jerburdett/)
 * Last activity: [13 years, 9 months ago](https://wordpress.org/support/topic/javascript-being-naughty/#post-2971988)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
