Solved

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

Posted on 2014-01-13
11
228 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 33

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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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 33

Expert Comment

by:Big Monty
ID: 39780951
post the link to the tutorial and maybe we can figure out how it works
0
 

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

ScreenConnect 6.0 Free Trial

Discover new time-saving features in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
align Linkedin sign to the right page 5 35
How to hyperlink a document in MS Word w/o full path 1 30
Google Maps API and PHP 25 30
Javascript_Set_dropdown_value 7 32
Why do we like using grid based layouts in website design? Let's look at the live examples of websites and compare them to grid based WordPress themes.
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

773 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