Page 1 of 1

Redirect using textbox value

Posted: Thu Nov 27, 2008 5:45 pm
by Aravinthan
~pickle | Please use [ code=html ], [ code=php ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: :arrow: Posting Code in the Forums to learn how to do it too.


Hi,
I made a code that takes the value of a text and transfers the user to a page representing what their wrote.

Its like a search form. User types the player name. And when they click the submit button it brings them to the player page.
Here is the coding:

Code: Select all

 
<script>
    function search()
        {
            name =  document.getElementById("inputString").value;
            window.location = "http://www.aoe3clan.com/index.php?name=Division1" + name;
        }
</script>
 
and the input box

Code: Select all

 
            <form name="search">
                <div>
                    Search a Player (Division 1):
                    <br />
 
                    <input type="text" size="30" value="" id="inputString" name="name" onkeyup="lookup(this.value);" onblur="fill();" />&nbsp;&nbsp;<input type="submit" value="View Player" onClick="search()"/>
                </div>
 
                <div class="suggestionsBox" id="suggestions" style="display: none; z-index: 500;">
                                    <div class="suggestionList" id="autoSuggestionsList">
 
                        &nbsp;
                    </div>
                </div>
 
            </form>
 
But it brings user to the wrong link.
It brings user to:
But it isnt the link I said.
And I tried removing the script. And when I clicked on submit button, it still went to
I took away the OnClick event and it STILL went to the page.... whats wrong? Its impossible that my FTP doesnt work. As everything else I change gets changed.....
Oh and I forgot to precise. These 2 codes are not full files. I use the php funciton include() to bring them toghter for other pages.
This is my code for teh index page:

Code: Select all

 
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<HTML>
<HEAD>
<TITLE> Menu
</TITLE>
<META NAME="Generator" CONTENT="TextPad 4.6">
<META NAME="Author" CONTENT="?">
<META NAME="Keywords" CONTENT="?">
<META NAME="Description" CONTENT="?">
<?php include("script.php"); ?>
</HEAD>
<body>
<?php include("nav.php"); ?>
 
<table width="100%" cellpadding="0" border="0" cellspacing="0">
 <tr>
  <td style="width:15px; height:33px;" class="story-01"></td>
  <td class="story-02">Menu</td>
  <td style="width:14px; height:33px;" class="story-03"></td>
 </tr>
 <tr>
  <td style="width:15px;" class="story-04"></td>
  <td class="story-05">
  <center>
     <p>
   <span style="font-weight: bold">
 
<a href="http://www.aoe3clan.com/index.php?name=Division1&file=enter"> Add a Player</a></br>
<a href="http://www.aoe3clan.com/index.php?name=Division1&file=form"> Update a Player</a></br>
<a href="http://www.aoe3clan.com/index.php?name=Division1&file=delete"> Remove a Player</a></br>
<a href="http://www.aoe3clan.com/index.php?name=Division1&file=ladder"> View the Ladder</a></br>
</center>
 </td>
   <td style="width:14px;" class="story-06"></td>
  </tr>
  <tr>
   <td style="width:15px; height:43px;" class="story-07"></td>
   <td class="story-08">
   </td>
   <td style="width:14px; height:43px;" class="story-09"></td>
  </tr>
</table>
 
</BODY>
</HTML>
 
Thanks for your help,
Ara


~pickle | Please use [ code=html ], [ code=php ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: :arrow: Posting Code in the Forums to learn how to do it too.

Re: Redirect using textbox value

Posted: Thu Nov 27, 2008 5:54 pm
by pickle
Try returning false from your search() function. It may be possible that the submit button's actions are being executed after the function is called, but get executed before the function's redirection.

If that doesn't work, have the action triggered by something else - like a plain div with an ID - something that doesn't normally trigger an action.

Re: Redirect using textbox value

Posted: Thu Nov 27, 2008 6:05 pm
by Aravinthan
YOu mean in my script code instead of window.location blablablalba I jsut return false?

And plus, When I change the:

Code: Select all

 
<input type="submit"...
 
to

Code: Select all

 
<input type="button"...
 
It Doesnt work.
I tried also:

Code: Select all

 
<form name="search" onSubmit="search()">
 
But it Didnt work...

Re: Redirect using textbox value

Posted: Fri Nov 28, 2008 10:14 am
by pickle
Change your

Code: Select all

<input type="submit" value="View Player" onClick="search()"/>
to

Code: Select all

<div onclick = "search();">View Player</div>
Since you're triggering an action yourself, and pulling the value from a textfield, there's really no need to have the form.