JavaScript - search box functionality
Asked By bipin pathak on 20-Jun-12 11:01 AM
hi all
i have a website which is built in html. It contain a search textbox in its top and i want that the search fuctionality should work on it ie whatever the word from website material like tab name or keywordsi enter into it and press the submit button it should redirect to the page which contain that word or sentence.
And the word or sentence to be inserted is from website only .
as ths is very important for me kindly reply me an appropriate answer
thanks
Mir Ishaq replied to bipin pathak on 20-Jun-12 11:23 AM
Hi Bipin
You shouldn´t use client javascript to access databases for several reasons (bad practice, security issues, etc) but if you really want to do this, here is an example:
var connection = new ActiveXObject("ADODB.Connection") ;
var connectionstring="Data Source=<server>;Initial Catalog=<catalog>;User ID=<user>;Password=<password>;Provider=SQLOLEDB";
connection.Open(connectionstring);
var rs = new ActiveXObject("ADODB.Recordset");
var searchvalue = document.getelementbyid('Yourtextboxname')
rs.Open("SELECT * FROM table", connection);
rs.MoveFirst
while(!rs.eof)
{
document.write(rs.fields(1));
rs.movenext;
}
rs.close;
connection.close;
you can modify the above program segment according to ur need.
Regards
Ishaq
Mir Ishaq replied to bipin pathak on 20-Jun-12 11:23 AM
Hi Bipin
You shouldn´t use client javascript to access databases for several reasons (bad practice, security issues, etc) but if you really want to do this, here is an example:
var connection = new ActiveXObject("ADODB.Connection") ;
var connectionstring="Data Source=<server>;Initial Catalog=<catalog>;User ID=<user>;Password=<password>;Provider=SQLOLEDB";
connection.Open(connectionstring);
var rs = new ActiveXObject("ADODB.Recordset");
rs.Open("SELECT * FROM table", connection);
rs.MoveFirst
while(!rs.eof)
{
document.write(rs.fields(1));
rs.movenext;
}
rs.close;
connection.close;
you can modify the above program segment according to ur need.
Regards
Ishaq
Mir Ishaq replied to bipin pathak on 20-Jun-12 11:23 AM
Hi Bipin
You shouldn´t use client javascript to access databases for several reasons (bad practice, security issues, etc) but if you really want to do this, here is an example:
var connection = new ActiveXObject("ADODB.Connection") ;
var connectionstring="Data Source=<server>;Initial Catalog=<catalog>;User ID=<user>;Password=<password>;Provider=SQLOLEDB";
connection.Open(connectionstring);
var rs = new ActiveXObject("ADODB.Recordset");
rs.Open("SELECT * FROM table", connection);
rs.MoveFirst
while(!rs.eof)
{
document.write(rs.fields(1));
rs.movenext;
}
rs.close;
connection.close;
you can modify the above program segment according to ur need.
Regards
Ishaq
bipin pathak replied to Mir Ishaq on 20-Jun-12 11:30 AM
thanks ishaq
it was a bit helpful.
[)ia6l0 iii replied to bipin pathak on 20-Jun-12 12:08 PM
The best solution to leverage, according to me, is to implement Google Site Search. If you already have your site live on the internet, you can test this feature in the below said url. You can get a live preview of search on the site you mention.
Please visit the following link for a quick tour, and resources.
http://www.google.com/enterprise/search/products_gss.html
And also note that you for sure have certain tricks that can let you search any website using search engines. For e.g. in google, "site:eggheadcafe.com robbe" searches eggheadcafe for the word robbe.Obviously, your website should be indexed and uptodate by the search engine.
Also you would be interested to know, that there are age-old Javascript search engines like JSSIndex, that can index a certain collection of webpages, and then let you search as well. Search about "jssindex" and you shall find more info on that.
Hope this helps.
Jitendra Faye replied to bipin pathak on 21-Jun-12 12:36 AM
Try this code , which will help you to search particular string in web page.
Reference from-
http://www.javascripter.net/faq/searchin.htm
solution-
var TRange=null;
function findString (str) {
if (parseInt(navigator.appVersion)<4) return;
var strFound;
if (window.find) {
// CODE FOR BROWSERS THAT SUPPORT window.find
strFound=self.find(str);
if (!strFound) {
strFound=self.find(str,0,1);
while (self.find(str,0,1)) continue;
}
}
else if (navigator.appName.indexOf("Microsoft")!=-1) {
// EXPLORER-SPECIFIC CODE
if (TRange!=null) {
TRange.collapse(false);
strFound=TRange.findText(str);
if (strFound) TRange.select();
}
if (TRange==null || strFound==0) {
TRange=self.document.body.createTextRange();
strFound=TRange.findText(str);
if (strFound) TRange.select();
}
}
else if (navigator.appName=="Opera") {
alert ("Opera browsers not supported, sorry...")
return;
}
if (!strFound) alert ("String '"+str+"' not found!")
return;
}

search textbox .NET Framework
hey all, i have a search textbox on my page and when the user hits the search button i create a parameterized query to get the results. when i enter a search criteria on the page that has angle brackets i get the following error message: System please tell me how to prevent this error? thanks, rodchar ASP.NET Discussions TxtFindSubject (1) Textbox (1) Rodchar (1) Src (1) Already answered in this very same newsgroup only 10 hours how to prevent application stops? Date: Tue, 10 Jul 2007 12:29:42 -0500 keywords: search, textbox description: hey all, i have a search textbox on my page and when the
I have userform with two textboxes at top, one labelled as 'search textbox'.I have listbox labelled as 'search results'.The other textbox labelled 'result textbox'. If a user enters 3 letters in search text box', basing on a formula, results of that formula will display in listbox.After
Dropdown button with "search" Textbox using C# Silverlight / WPF 28-Oct-12 08:08 PM Hi, I have to add a "Search Box" with a DropDown Button for searching the books. This dropdown button should have an arrow pointing downwards and the search textbox next to it. so, wen i click on dropdown button, i should get few options like team, personal, e. . . . . . . . ) If i select Team then the text "Search in Team" should be displayed in the textbox. A small magnifier for the searchbox will be available too. I am using C#, XAML However, I have needed to do something similar in WinForms. I cheated, I placed a TextBox on top of a ComboBox and lined up the borders. I then subscribed to the
I have tried to have the query is not clear what you want to do actually if you want to put search textbox on you page and than get search result from database display into gridview than you need to fill DataSet based on like query on search text input in the search textbox and than bind that dataset to gridview. HI, Try the below code. / / add namespace using
Hello All, I have a search textbox and a search button. when i enter value and click in the textbox i want the search button click event to fire automatically. Can someone help please? Thanks. From where you want to search? from database column? then use LIKE operator( The LIKE operator is used in a WHERE clause to search for a specified pattern in a column.) SELECT column_name(s) FROM table_name WHERE column_name LIKE
Hello, I have a textbox that I insert a string into, to search within a listbox. Everything runs great and I get the information I need returned to me. Now I want to be able to insert 2 strings into this textbox and search for multiple possibilities within the listbox. In other words, If I input the word "Read iterates through the collection in the listbox and returns whatever line(s) that contain that search string. Now, I want to be able to input into the textbox, "Read" and "Written" and return all the lines that contain both of these words in
Hi All, i have devloped application, to filter records presented in gridview.so that when user type his name in search textbox then only records related to him will appear in gridview with update and delete button record is selected for updation . i want to handle this problem, so that when user search his record and in the filtered gridview try to update his record then it will select query without any filter to show records in gridview. Now when you click on search button, there are two options to filter the data. 1. you pass the value of search Textbox and compare the column in database query, and get filtered records from database directly, then
08:08 PM Hi, i have a listView ItemCreated Event and want to find a textbox Id wich is generated. I used to do like this: TextBox textBox = (TextBox) e.Item.FindControl( "textBoxServer" ); string temp = textBox.ClientID; These gives me something like "ct100textBoxServer". But it needs to contains the Path of Masterpages like " ctl00_ctl00_cphMstrMain_cphMstrDocuments_ctl00_listViewBookmarks". I think i have to search with something like this: e.Item.FindControl("textBoxServer").Parent; To find a control on master the FindControl method to get a reference to two controls on the master page, a TextBox control and a Label control. Sub Page_Load() Dim mpContentPlaceHolder As ContentPlaceHolder Dim mpTextBox As TextBox mpContentPlaceHolder = _ CType(Master.FindControl("ContentPlaceHolder1"), _ ContentPlaceHolder) If Not mpContentPlaceHolder Is Nothing Then mpTextBox
TextBox in Master Page .NET Framework
I have a search TextBox in a Master Page that I am using in a SelectParameter of a GridView. After and doing a postback the text disappears. How can I retain the text in the TextBox located in the Master Page? Thanks. David ASP.NET Discussions GridView (1) TextBox (1) GridViewTextBox (1) Load (1) SelectParameter (1) MasterPage (1) do you have viewstate enabled? Yes controls in Gridview must trigger a postback to the original page first so that the TextBox content can be stored in Session. Redirection or transfer to another page can then proceed but the code for restoring the textbox in the Master page will have to be executed at the destination page (code can controls in Gridview must trigger a postback to the original page first so that the TextBox content can be stored in Session. Redirection or transfer to another page can then proceed
content from content page ASP.NET 28-Oct-12 07:52 PM i hav a search textbox in master page and i want to access that textbox from content page. what are the ways by which i can achieve this. pls any control because everything is control in the page and all controls are inherited from Control: TextBox tb = (TextBox)Master.FindControl( "txtInMasterPage" ); Hello, Here is code for you. ContentPlaceHolder masterPagePlaceHolder; TextBox masterPageTextBox; masterPagePlaceHolder = (ContentPlaceHolder)Master.FindControl( "ContentPlaceHolder1" ); if (masterPagePlaceHolder ! = null ) { masterPageTextBox = (TextBox) masterPagePlaceHolder.FindControl( "TextBox1" ); } / / for control outside Content Placeholder Label masterPageLabel = (Label) Master.FindControl( "masterPageLabel" ); Thank you. keywords: ContentPlaceHolder, TextBox, ASP.NET, FindControl, Control description: accessing master page content from content page i hav a