views:

3223

answers:

5

Here's the scenario:

I have a textbox and a button on a web page. When the button is clicked, I want a popup window to open (using Thickbox) that will show all items that match the value entered in the textbox. I am currently using the IFrame implementation of Thickbox. The problem is that the URL to show is hardcoded into the "alt' attribute of the button. What I really need is for the "alt" attribute to pass along the value in the textbox to the popup.

Here is the code so far:

<input type="textbox" id="tb" />
<input alt="Search.aspx?KeepThis=true&TB_iframe=true&height=500&width=700" class="thickbox" title="Search" type="button" value="Search" />

Ideally, I would like to put the textbox value into the Search.aspx url but I can't seem to figure out how to do that. My current alternative is to use jQuery to set the click function of the Search button to call a web service that will set some values in the ASP.NET session. The Search.aspx page will then use the session variables to do the search. However, this is a bit flaky since it seems like there will always be the possibility that the search executes before the session variables are set.

A: 

Here is an idea. I don't think it is very pretty but should work:

$('input#tb').blur(function(){ 
  var url = $('input.thickbox').attr('alt');
  var tbVal = $(this).val();

  // add the textbox value into the query string here
  // url = ..

  $('input.thickbox').attr('alt', url);

});

Basically, you update the button alt tag every time the textbox loses focus. Instead, you could also listen to key strokes and update after every one.

As far as updateing the query string, I'll let you figure out the best way. I can see putting a placeholder in there like: &TB=TB_PLACEHOLDER. Then you can just do a string replace.

Ricky
Tried that. The alt definitely takes effect but it doesn't appear that the Thickbox plugin is respecting it. It still uses the original URL. :-(
Kevin Pang
+8  A: 

why not just handle onclick of your button to run a function that calls tb_show() passing the value of the text box. Something like ....

... onclick = "doSearch()" ...

function doSearch()
{
    tb_show(caption, 'Search.aspx?KeepThis=true&q=\"' + 
            $('input#tb').val() + 
            '\"&TB_iframe=true&height=500&width=700');

}

Scott Evernden
That is EXACTLY what I was looking for. Thank you! If I could vote you up 10 times I would. :-)
Kevin Pang
A: 

2009 News! Check out this blog post about using LiveQuery plugin to do that http://www.codynolden.com/blog/2009/01/thickbox-and-ajax-using-livequery/

Works like a charm!

Eduardo Molteni
A: 

In the codebehind you could also just add the alt tag progamaticly.

button1.Attributes.Add("alt", "Search.aspx?KeepThis=true&TB_iframe=true&height=500&width=700");
TheAlbear
A: 

If you read the manual, under the iframe content section, it tells you that your parameters need to go before the TB_iframe parameter. Everything after this gets stripped off.