I need to create a link to search Google with a specific text. To do this, I have to replace the spaces in the text with '+' and include it in the href attribute.
Here is how it can be done in HTML:
<a href="#" id="afd_gsearch">Search Google</a>
<script>
set("my search string");
</script>
And here is the JavaScript code:
function set(text) {
$("#afd_gsearch").attr('href', "https://www.google.com/search?q=" + gsearchquery(text));
}
function gsearchquery(text) {
var query = text.replace(" ", "+");
return query;
}