SitePoint Sponsor |
|
User Tag List
Results 1 to 6 of 6
Thread: Auto Quotes in forms
-
Nov 14, 2006, 22:00 #1
- Join Date
- Mar 2006
- Posts
- 5
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
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
-
Nov 14, 2006, 22:21 #2
- Join Date
- Sep 2005
- Location
- Tanzania
- Posts
- 4,662
- Mentioned
- 2 Post(s)
- Tagged
- 0 Thread(s)
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>
Code:document.getElementById('submit').onclick = function () { var keywords = '"' . document.getElementByName('keywords').value . '"'; document.getElementByName('keywords').value = keywords; document.getElementById('aform').submit(); }
-
Nov 14, 2006, 23:08 #3
- Join Date
- Mar 2005
- Location
- USA
- Posts
- 5,482
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Raffles, there is no document.getElementByName() function. You probably want document.getElementsByName().
Code:document.getElementsByName('keywords')[0]
We miss you, Dan Schulz.
Learn CSS. | X/HTML Validator | CSS validator
Dynamic Site Solutions
Code for Firefox, Chrome, Safari, & Opera, then add fixes for IE, not vice versa.
-
Nov 15, 2006, 17:00 #4
- Join Date
- Sep 2005
- Location
- Tanzania
- Posts
- 4,662
- Mentioned
- 2 Post(s)
- Tagged
- 0 Thread(s)
Whoops, that's what I meant. Cheers Kravvitz.
-
Nov 16, 2006, 18:53 #5
- Join Date
- Mar 2006
- Posts
- 5
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Thanks guys
-
Nov 17, 2006, 08:51 #6
- Join Date
- Dec 2003
- Location
- Cheltenham, United Kingdom
- Posts
- 692
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
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.
Olly Hodgson
thinkdrastic.net
Bookmarks