Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Redirect to a page concatenating a text field value using javascript.

Posted on 2011-03-19
6
Medium Priority
?
281 Views
Last Modified: 2012-05-11
I have this asp.net code.

I need to redirect to a page
llike
searchresults.aspx?Keyword=[What the user typed in the search box]

I need to do it on the imagebutton below.
<asp:TextBox id="searchTextBox" runat="server" CssClass="water" Text="Zoek"></asp:TextBox>


<asp:ImageButton  ImageUrl="/Style Library/Aurelium/images/layout/header-search-btn.png" ID="srchImage" runat="server" title="Zoek"></asp:ImageButton>
              
0
Comment
Question by:LuisEstebanValencia
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 2

Expert Comment

by:michael_madsen
ID: 35172749
Put this in you header (somewhere between <head> and </head>):

<script language="javascript">
function SearchRedirect()
{
    var objSearchTextBox = document.getElementById("searchTextBox");
    document.location.href = "searchresults.aspx?Keyword=" + objSearchTextBox.value;
}
</script>

and then modify you button like:

asp:ImageButton  ImageUrl="/Style Library/Aurelium/images/layout/header-search-btn.png" ID="srchImage" runat="server" title="Zoek" OnClientClick="SearchRedirect();return false;"></asp:ImageButton>
0
 

Author Comment

by:LuisEstebanValencia
ID: 35173235
Hello, it works but I still have a problem.

The sharepoint search results page is in a specific folder
/search/results.aspx

I need that this code works from any place in the website and the code you sent me is to be placed on a masterpage

 document.location.href = "~/search/results.aspx?k=" + objSearchTextBox.value;


the problem is that the ~ token seems that doesnt work in javascript, can you please help me with  this.

Thank you
0
 
LVL 82

Expert Comment

by:leakim971
ID: 35173427
So use the full path :

document.location.href = "http://www.yourdomain.extension/path/to/search/results.aspx?k=" + objSearchTextBox.value;

Open in new window

0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:LuisEstebanValencia
ID: 35174799
I cant use the full path, right now I am on development environment and I have somethng as http://mycomputername

when I deploy this to staging or production that wouldnt work
I need a generic way to point to the root using javascript and that I dont have to change code when moved to another environment

thanks
0
 
LVL 2

Accepted Solution

by:
michael_madsen earned 2000 total points
ID: 35177085
Sorry for not returning until now.

Please change:

    document.location.href = "searchresults.aspx?Keyword=" + objSearchTextBox.value;

to:

    document.location.href = "/search/results.aspx?k=" + objSearchTextBox.value;

(provided that the full path is: "http://<hostname>/search/results.aspx?k=something")
0
 

Author Closing Comment

by:LuisEstebanValencia
ID: 35179133
perfect
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

670 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question