2

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

1 Answer 1

7

You need to call the replace function, like this:

$('#searchButton').click(function() { 
    alert(theUrl.replace('%s', $('#searchBox').val());
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.