Solved

Creating a search field that will search our website and produce results

Posted on 2014-01-13
11
226 Views
Last Modified: 2014-01-22
I have created a search field for our website and when I test it, it just goes back to the home page.  Here is the code:

<form action="http://www.companysite.com" method="post" class="search-form">
    	<label for="search">Search</label>
    	<input type="search" placeholder="Search" title="Search" class="q" name="search" id="search">
    	<input type="submit" class="submit" value="Go" name="submit">
</form>

Open in new window


What am I doing wrong?

Thanks,
John
0
Comment
Question by:jebolton
  • 5
  • 4
  • 2
11 Comments
 
LVL 52

Accepted Solution

by:
Scott Fell,  EE MVE earned 500 total points
ID: 39778210
Either you need to use some type of server side code that will search your database or an index OR you are using https://developers.google.com/custom-search/ or I keep forgetting about bing http://www.bing.com/blogs/site_blogs/b/developer/archive/2010/03/22/add-a-bing-search-box-to-your-site-in-3-easy-steps.aspx
0
 
LVL 32

Expert Comment

by:Big Monty
ID: 39780264
it's going back to the homepage because your action attribute in your form tag is set to your home page. how exactly are ypu producing the results?
0
 

Author Comment

by:jebolton
ID: 39780816
I got it through a tutorial.  I'm thinking I need a cgi script or a javascript to fix this problem.

I looked into the google and bing custom search and I'm wondering if there is a free (ad free) script out there that would do the job.  My deadline prevents me from learning the code and creating my own version at this point.
0
 
LVL 52

Expert Comment

by:Scott Fell, EE MVE
ID: 39780942
If you don't mind going to another tab to google there is always

 <form action="https://google.com/search" method="get" target="_blank">
    Search me<br>
    <input name="q"><br>
    <button type="submit">Search</button>
    
  </form>

Open in new window


Or use serverside code to direct to

https://www.google.com/search?q=site:yourdomaine.com+search_term
0
 
LVL 32

Expert Comment

by:Big Monty
ID: 39780951
post the link to the tutorial and maybe we can figure out how it works
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:jebolton
ID: 39781058
Scott,
  So would I put the "server side" code mentioned above after the action statement in parentheses?
0
 
LVL 52

Expert Comment

by:Scott Fell, EE MVE
ID: 39781115
>So would I put the "server side" code mentioned above after the action statement in parentheses?

I meant use php/asp and process but you could just use javascript.

http://jsbin.com/aquWEDa/2/edit

<!DOCTYPE html>
<html>
<head>

<meta charset=utf-8 />
 
<script>
function searchMe(){
	var myTextField = document.getElementById('myText');
	if(myTextField.value != "")
		window.open("https://www.google.com/search?q=site:yourdomaine.com+" + myTextField.value)
	else
		alert("Please enter a search term")		
}
</script>
<title>JS Bin</title>
</head>
<body>
<input type='text' id='myText' />
<input type='button' onclick='searchMe()' value='Search' />

</body>
</html>

Open in new window

0
 

Author Comment

by:jebolton
ID: 39786777
I have decided to go the Google custom search route.  I have it working on the site but I need to customize it to fit the are I want to put it.
0
 

Author Comment

by:jebolton
ID: 39799945
What I ended up doing was to purchase the Google site search.  Working with the support specialist and the ability to remove ads, it was well worth the purchase.  The search feature is up and running in the design and format that I wanted.  Thanks for the insights and suggestions.
0
 

Author Closing Comment

by:jebolton
ID: 39799953
Thanks for your help Scott.
0
 
LVL 52

Expert Comment

by:Scott Fell, EE MVE
ID: 39799967
I think that was the best choice to use custom search! and pay!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Building a website can seem like a daunting task to the uninitiated but it really only requires knowledge of two basic languages: HTML and CSS.
This article discusses four methods for overlaying images in a container on a web page
In this tutorial viewers will learn how to code links for mobile sites that, once clicked, send a call or text to a specified number. For a telephone link (once clicked, calls a number), begin with a normal "<a href=" link tag. For the href, specify…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now