JavaScript Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsWeb DesignJavaScript Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old December 24th, 2012, 09:17 AM
foxtail foxtail is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2009
Posts: 64 foxtail User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 h 57 m 37 sec
Reputation Power: 5
jQuery - Modifying form action for Google Search Appliance

I'm attempting to create a custom HTML form which submits the query to the Google Search Appliance. The results are displayed in an iframe.

Problem being is the action from the form:
http://search1.dot.state.mn.us/search?q=test&btnG=Search&site=clips01&site=clips02&client=newsline&output=xml_no_dtd&proxystylesheet=newsline&getfields=*&filter=0&num=5&proxyreload=1

I have multiple collections and I need to search across them based on the check-boxes the user selects.Problem is the:

&site=clips01&site=clips02&site=clips03&site=clips04
Needs to be:
&site=clips01|clips02|clips03|clips04

I currently have this:
Code:
$(document).ready(function() {
  $('#newsclips').submit(function() {
    //Get the values from the form and place them in a string
    var values = $(this).serialize();

    //Change the values for &site= ???

    //Modify the action of the form
    var action = "http://search1.dot.state.mn.us/search?" + values;
    $(this).attr('action', action);
}); });


Not sure if this is the best way, I figured I could do a search & replace on the string after it was serialized. I couldn't figure out how to get it to work correctly so I stripped it out of the code I currently have and looking for a better way. Any ideas?

This is the full string being sent in the action:
Code:
http://searchappliance/search?q=test&btnG=Search&site=clips01&site=clips02&client=newsline&output=xml_no_dtd&proxystylesheet=newsline&getfields=*&filter=0&num=5&proxyreload=1

Reply With Quote
  #2  
Old December 24th, 2012, 11:29 AM
foxtail foxtail is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2009
Posts: 64 foxtail User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 h 57 m 37 sec
Reputation Power: 5
Update!

So I'm using this code and the alerts look correct, but it doesn't seem to be actually modifying the "action" attribute correctly. If I change "searchappliance" to "testsearchappliance" that seems to work correctly, but the parameters after it are not being set correctly. It's like the form is over-writing my action somehow?

**Update - Ok, so what I believe is occurring is the action is correctly updated, but the way the form works is that it overwrites anything past the "search?" with the parameters on the form before submitting it to the iframe.

I attempted to "event.preventDefault()" but that just puts it into and endless loop as the function itself is an event listener. Even if I add another submit() at the bottom of the script. So now I think I know what is occurring, just not sure how to resolve it.

This site, URL re-write using PHP for Google Search Appliance , shows how to do it using PHP which I may have to switch to. Not sure how it will work with an iFrame on the page.

Code:
$('#newsclips').submit(function(event) {
  //Get the values from the form and place them in a string
  var values = $(this).serialize();
  alert (values); 

  //Modify the values to remove the &site=
  values = values.replace(/&site=/ig,'|');
  values = values.replace(/\|/i,'&site=');
  alert (values);

  //Modify the action of the form 

  var newAction = "http://searchappliance/search?" + values;  
  $(this).attr('action', newAction);
  alert (newAction);
}); 

Last edited by foxtail : December 24th, 2012 at 02:28 PM.

Reply With Quote
Reply

Viewing: Dev Shed ForumsWeb DesignJavaScript Development > jQuery - Modifying form action for Google Search Appliance

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap