473,395 Members | 1,616 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Code For Creating User Input Box In Google AJAX News Bar?

3
Does anyone know the code to insert into a standard AJAX Google News Bar code which would allow a user to input a name from which to have the News Bar search.

Currently, the News Bar code only searches out names entered as the "name" within the code itself entered by the programmer. Looking for a way to allow users to input a name from the News Bar itself.

EG- Input Box Displays News

Current coding is:

Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2.     function LoadNewsBar() {
  3.       var newsBar;
  4.       var options = {
  5.         largeResultSet : true,
  6.         title : "In the news",
  7.         horizontal : true,
  8.         linkTarget : GSearch.LINK_TARGET_BLANK,
  9.         autoExecuteList : {
  10.           executeList : ["keyword"]
  11.         }
  12.       }
  13.  
  14.       newsBar = new GSnewsBar(document.getElementById("newsBar-bar"), options);
//-->where "keyword" can be any word
Would like to be able to allow the web page user to enter the keyword to search within the News Bar itself...

Thanks...
May 19 '10 #1
3 2131
acoder
16,027 Expert Mod 8TB
If I'm following correctly, a text box which the user uses to input the keyword which you pass to the LoadNewsBar function:
Expand|Select|Wrap|Line Numbers
  1. function LoadNewsBar(keyword) {
and that's used in place of "keyword":
Expand|Select|Wrap|Line Numbers
  1. executeList : [keyword]
May 20 '10 #2
pcol
3
That doesn't work: and I haven't seen any code whereby any word is entered between the brackets after LoadNewsBar. The brackets are supposed to be empty The matter seems to be a simple one- yet I'm not an AJAX code writer. All I want to be able to do is have the user enter a keyword to search news by in the News Bar, rather than have the keywords being static as designated within the coding. Thanks for your reply, though...
May 21 '10 #3
pcol
3
So for example the below code is the ajax code to create a search box for the user to do a google search- and I would imagine that this code can be integrated into the NewsBar code to do what I'm looking to do:

Expand|Select|Wrap|Line Numbers
  1. google.load('search', '1');
  2.  
  3. var imageSearch;
  4.  
  5. function addPaginationLinks() {
  6.   // The cursor object has all things to do with pagination
  7.   var cursor = imageSearch.cursor;
  8.   var curPage = cursor.currentPageIndex; // check what page the app is on
  9.   var pagesDiv = document.createElement('div');
  10.   for (var i = 0; i < cursor.pages.length; i++) {
  11.     var page = cursor.pages[i];
  12.     if (curPage == i) { // if we are on the curPage, then don't make a link
  13.       var label = document.createTextNode(' ' + page.label + ' ');
  14.       pagesDiv.appendChild(label);
  15.     } else {
  16.       // If we aren't on the current page, then we want a link to this page.
  17.       // So we create a link that calls the gotoPage() method on the searcher.
  18.       var link = document.createElement('a');
  19.       link.href = 'javascript:imageSearch.gotoPage('+i+');';
  20.       link.innerHTML = page.label;
  21.       link.style.marginRight = '2px';
  22.       pagesDiv.appendChild(link);
  23.     }
  24.   }
  25.  
  26.   var contentDiv = document.getElementById('content');
  27.   contentDiv.appendChild(pagesDiv);
  28. }
  29.  
  30. function searchComplete() {
  31.   // Check that we got results
  32.   if (imageSearch.results && imageSearch.results.length > 0) {
  33.     // Grab our content div, clear it.
  34.     var contentDiv = document.getElementById('content');
  35.     contentDiv.innerHTML = '';
  36.  
  37.     // Loop through our results, printing them to the page.
  38.     var results = imageSearch.results;
  39.     for (var i = 0; i < results.length; i++) {
  40.       // For each result write it's title and image to the screen
  41.       var result = results[i];
  42.       var imgContainer = document.createElement('div');
  43.  
  44.       var title = document.createElement('div');
  45.       // We use titleNoFormatting so that no HTML tags are left in the title
  46.       title.innerHTML = result.titleNoFormatting;
  47.  
  48.       var newImg = document.createElement('img');
  49.       // There is also a result.url property which has the escaped version
  50.       newImg.src = result.tbUrl;
  51.  
  52.       imgContainer.appendChild(title);
  53.       imgContainer.appendChild(newImg);
  54.  
  55.       // Put our title + image in the content
  56.       contentDiv.appendChild(imgContainer);
  57.     }
  58.  
  59.     // Now add the paging links so the user can see more results.
  60.     addPaginationLinks(imageSearch);
  61.   }
  62. }
  63.  
  64. function OnLoad() {
  65.   // Our ImageSearch instance.
  66.   imageSearch = new google.search.ImageSearch();
  67.  
  68.   // Restrict to extra large images only
  69.   imageSearch.setRestriction(google.search.ImageSearch.RESTRICT_IMAGESIZE,
  70.                              google.search.ImageSearch.IMAGESIZE_MEDIUM);
  71.  
  72.   // Here we set a callback so that anytime a search is executed, it will call
  73.   // the searchComplete function and pass it our ImageSearch searcher.
  74.   // When a search completes, our ImageSearch object is automatically
  75.   // populated with the results.
  76.   imageSearch.setSearchCompleteCallback(this, searchComplete, null);
  77.  
  78.   // Find me a beautiful car.
  79.   imageSearch.execute("Subaru STI");
  80. }
  81. google.setOnLoadCallback(OnLoad);
May 21 '10 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Renie83 | last post by:
Hi I really am going crazy! I'm using VBScript, ASP, and SQL My page reminds me of a shopping cart but looking at shopping cart examples has not helped! What I have is a page that brings in...
0
by: Ray Lavelle | last post by:
I'm new to VB .NET. In the past when creating an application, if I had an input form I would just call the set and get methods on the object that mapped to my database table in order to store and...
12
by: agent349 | last post by:
Hi, I'm fairly new to c++. I need user input in the form of dollar amounts, ie: "$10.00". I'd like to remove the dollar sign "$" then store the rest in a variable. How do I go about removing the...
3
by: Clare | last post by:
Hi I have a report that is made of 4 subreports. There is no actual information in the main report, and the record source is empty. In the Header section of the main report, I have a text box...
7
by: Daniel Walzenbach | last post by:
Hello, I want to create a Word XML file based on the input users make in a VB.NET application. I imagine creating a template in Word and saving it as a XML file. I then want to fill the...
2
by: josephm | last post by:
Hello Group: My first post on the group.Hope I get a response. I have a modest Fire Insurance ACCES Db.Thanks to this group - for the code. A "wanna be programmer"... "LEARNS" The code...
9
by: chuck | last post by:
I need some help with validating user input. I am writing a C computer program for an intro to C course. Here is the situation. I am creating an application that will do currency conversions. ...
3
by: ecpbm765 | last post by:
Hey, I am helping to develop a project that displays images based on user input. One possible way of implementing this is via a widget that when it is run, would read in the users input from an...
0
by: phl | last post by:
hello, I am trying to explore options on the various types of search engines for searching user input. User input maybe stored in XML files. Does anyone know if there are any good ready made...
2
by: John c | last post by:
I have looping code in Access which generates Excel spreadsheets and prints them off. They can run to hundreds and at present, once the code starts to run there is no way it can stop cleanly part...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.