Solved

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

Posted on 2011-03-19
6
272 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
  • 3
  • 2
6 Comments
 
LVL 2

Expert Comment

by:michael_madsen
Comment Utility
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
Comment Utility
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
Comment Utility
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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 

Author Comment

by:LuisEstebanValencia
Comment Utility
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 500 total points
Comment Utility
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
Comment Utility
perfect
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
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…

744 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now