views:

53

answers:

1

Hello,

I have a variable like

var theUrl = 'http://www.google.com/?q=%s';

then i have a input box like

<input type="text" id="searchBox" value="" />

and a button like

<input type="button" id="searchButton" value="Search" />

when the button is clicked, i should get a alert where the %s of the var theUrl should be replaced with the user entered text in the textbox

How to do this ? i think find() function only replaces html elements !

Please help

+5  A: 

You need to call the replace function, like this:

$('#searchButton').click(function() { 
    alert(theUrl.replace('%s', $('#searchBox').val());
});
SLaks