-
Auto Quotes in forms
I am putting a search engine on a website. I can either use JS or xhtml but in order to get a correct return I need to automatically put quotes around the input. It is a golf site and will be large. If someone searched for "golf clubs" it would show 4 articles which is the correct amount. If the searched for golf clubs without the quotes everything in the site will show up and that could be as many as 500 articles. I know even if i asked them to put quotes around their search phrase many will not. How can I have the quotes automatically entered around the search term?
Thank you
Don Young
-
You'll have to use javascript for this. Something like this:
HTML Code:
<form id="aform" method="get" action="golf.php">
<input type="text" name="keywords" />
<input type="button" id="submit" value="Go" />
</form>
Then in your JS you put:
Code:
document.getElementById('submit').onclick = function () {
var keywords = '"' . document.getElementByName('keywords').value . '"';
document.getElementByName('keywords').value = keywords;
document.getElementById('aform').submit();
}
There may be a better way to do it though, but that's how I would do it.
-
Raffles, there is no document.getElementByName() function. You probably want document.getElementsByName().
Code:
document.getElementsByName('keywords')[0]
-
Whoops, that's what I meant. Cheers Kravvitz.
-
-
Not that'll only work if they have javascript enabled. You'd be much better off handling this on the server side. Also, that script doesn't take into account and "" they've added already.