JavaScript - Append A String To Search Query After Clicking Submit/search Button
In this case, Let's take Google Search as example:
The code is JScript .NET, which is basically a .NET version of Javascript. Regardless of language, Anyone with appending type of skill can answer my question. This code is used in Fiddler(It's a Man-in-the-middle proxy) Code: if (oSession.uriContains("&q=")) // oSession is a Fiddler object session // uriContains() function, checks for case-insensitive string from the URI { var str = oSession.fullUrl; var sAppend = "test1+test2+test3"; if (!oSession.uriContains(sAppend)) { oSession.fullUrl = str.replace( "&q=","&q="+sAppend); } } For those who are confused, It says, If &q= is present in the URI, replace/append &q= with &q=test1+test2+test3 Problem: It appends test1+test2+test3 instantly, when it sees &q= in the URL. Basically, how do I make it wait until I click the submit/search button Thank you. Update: I heard about Onsubmit() event, but not really familiar with it. How do I use it? like, should I go to google source page and edit the form id? Also, Any other methods besides Onsubmit()? Similar TutorialsThe code is JScript .NET, which is basically a .NET version of Javascript. Regardless of language, Anyone with appending type of skill can answer my question. The problem is, when I keep issuing the request it keeps appending over and over again Code: if (oSession.uriContains("search?q=")) { var str = oSession.fullUrl; var sAppend = "+test1+test2+test3"; if (!oSession.uriContains(sAppend)) { oSession.fullUrl = str.replace( "search?q=","search?q="+sAppend); } } Can you please give me an example? I'm still new to programming. Thank you Hey all, I'm in process of writing my own script (I don't want to use any jquery plugins) to render a table and allow for filtering/searching. So when user clicks on link, by default there will be parameters passed in query string as you can see in the setDefaults private method below. However, I'm stuck trying to figure out the best way to append values selected from filter dropdown to the query string. I know it will involve something along the lines of $("select").change(function(){var option = $(this).val()}). But I am having difficulty figuring out how to incorporate it with this. I would like to make use of the below buildFilter function somehow: Code: (function($){ var listview = $('#listview'); var lists = (function(){ var criteria = { drop_filter: { check: function(value){ if(value) return }, msg: "Loading..." }, search_filter: { check: function(value){ if(value) return }, msg: "Loading..." } } var handleFilter = function(){ } return { create: function(component){ var component = component.href.substring(component.href.lastIndexOf('#') + 1); return component; }, setDefaults: function(component){ var parameter = {}; switch(component){ case "sites": parameter = { 'order': 'site_num', 'per_page': '20', 'url': '/sites' } } return parameter; }, buildFilter: function(){ if(event == "change") return criteria.drop_filter(); } } })(); $('#dashboard a').click(function(){ var currentComponent = lists.create(this); var custom = lists.setDefaults(currentComponent); initializeTable(custom); }); var initializeTable = function(custom){ var defaults = {}; var query_string = $.extend(defaults, custom); var params = []; $.each(query_string, function(key,value){ params += key + ': ' + value; }) alert(params); } })(jQuery) Thanks for any response. Hey there everyone. I'm a bit of a newb with javascript and php so apologies if this question is a bit simple, although I can't get my head round how to go about doing it. I have a search page where a user can type in a search box, or they can use an alphabetical list to search for the record they're looking for. Eg they click 'a' and all the records beginning with the letter 'a' appear. I'd also like to have it so that each record has a number of tags, and I'd then like to be able to filter records according to which tags have been selected - preferably using checkboxes. For example, perhaps the tags would be colours and the records represented shoes. There'd be checkboxes for blue, yellow, black, brown and so on. At first all colours would be shown, but if the user clicks on brown the all but the brown shoes dissappear. like I say, I'm new to learning php so please be gentle. Also I'm using Cakephp so if there's anyway to make it easier using Cake then I'd love to know. thanks Hello Having problems with the following...a client needs me to replicate this contact page: http://www.ravenrow.org/contact/ In particular he wants the subscribe/unsubscribe to appear only when one enters text into the text field (as it does here). I have recently changed from using tables to div tags but this was the first website where I started to experiment with divs. Unfortunately therefore it is a mixture of tables and divs. But here is my page: http://www.rowingpresents.com/contact.html Can someone tell me what I need in my code to have to subscribe/unsubscribe appear and disappear as it does at ravenrow.org. Many thanks S I am using javascript to search for the '*' character in a string (ie. 'username*:') but using search('\*') does not work. How do I search for it since the search function takes a regexp argument and * messes that up?
Hello all I have search this topic but I can't really get a straightforward answer. I have been given a small assignment to make 4 checks. I'm not looking for handouts, the assignment itself is complete, but I just have this single problem. Check 1: make sure a radio button is checked (no problem) Check 2: make sure a string does not contain restricted characters (no problem) Check 3: make sure a string is of numbers only (issue 1) Check 4: make sure a string follows a certain format (issue 2) My problem lies with the <string>.value.search(/\D/) and <string>.value.search(/\d/). Dreamweaver does not want to recognize this as valid code. In turn, checks 3 and 4 do not execute. I have checked and re-checked for possible syntax errors, to no avail. I will attach my entire code and a screenshot of how Dreamweaver is handling my code. Code: <html> <head> <title>Payment Form</title> <script type="text/javascript"> function errorCheck() { //start card must be checked if ((document.form1.pmtType[0].checked == false) && (document.form1.pmtType[1].checked == false) && (document.form1.pmtType[2].checked == false) && (document.form1.pmtType[3].checked == false)) { window.alert("Please select one of the credit cards") return false } //end card must be checked //start name character check badChar = ";:!@#$%^*+?";length = badChar.length; for (i=0; i<length; i++) { if (document.form1.Name.value.indexOf(badChar.charAt(i)) != -1) { window.alert("The name you entered contains illegal characters (;:!@#$%^*+?). Please re-enter your name") document.form1.Name.focus() document.form1.Name.select() return false } } //end name character check //start card check for digits only if (document.form1.card.value.search(/\D/) != -1) { window.alert("Your bank account number should consist of digits only") document.form1.card.focus() document.form1.card.select() return false } //end card check for digits only //start exp date validation var xmonth; if (document.form1.date.value.search(/\d\d\/\d\d\d\d/) == 0) //proper format { xmonth = document.form1.date.value.charAt(0) + document.form1.date.value.charAt(1) if (xmonth<01) || (xmonth>12) { window.alert("Please enter a value between 01 and 12 for MM") document.form1.date.focus() document.form1.date.select() return false } else { return true } } else { window.alert("Please enter the date in proper format MM/YYYY") document.form1.date.focus() document.form1.date.select() return false } //end exp date validation return true } </script> </head> <body> <h1>Payment</h1> <form name="form1" onSubmit="return errorCheck()" action="mailto:johndoe@address.com" method="post"> <p> Credit card: <input type="radio" name="pmtType" value="Visa">Visa <input type="radio" name="pmtType" value="MasterCard">MasterCard <input type="radio" name="pmtType" value="American Express">American Express <input type="radio" name="pmtType" value="Discover">Discover </p> <p> Name on Credit Card: <input type="text" name="Name" size="50"> </p> <p> Credit Card Number: <input type="text" name"card" size="20" maxlength="20"> (No spaces or dashes, please) </p> <p> Expiration Date: <input type="text" name="date" size="7" maxlength="7"> (MM/YYYY) </p> <p> <input type="submit" value="Submit"> </p> </form> </body> </html> Thanks in advance, Matt I would like to find some direction or help to solve an issue I have. I would like to find a way to search for a string of content on my webpage and return the string, or at least part of the string into the URL... Example of the content on my page: ----- Welcome, John Adams Log Out Welcome to your own content, based on your settings provided. Feel free to download the content you need. ----- Fairly straightforward. Now I would like to create a function that will look at the page and "copy" the string of content beginning with "welcome" and ending with "out" Next, I would like to remove the "welcome," and "log out" and have the name remain. Then, post the name into the URL to be passed onto the next page for me to use as more personalization/dynamically driven content; Such as: http://www.noname.com/index.html?string=John-Adams Hopefully you can help. Hi, I am building a user model of web browsing behavior (chrome plug-in) and would like to capture any search query that is entered into google.com. When I view source I see that the form name is f and the input name is q, is there a reason that document.f.q.value is not working?? Any suggestions of what would work? Thank you I have noooo idea if I am even posting this in the correct area, let alone the correct site. If not I apologize and maybe someone could direct me elsewhere. I am trying to add a custom search into my site. http://www.jeffknowsloans.com you can see it about the middle of the page. I am using the following script to do so. Code: <script type="text/javascript"> function dosearch() { var sf=document.searchform; var submitto = sf.sengines.options[sf.sengines.selectedIndex].value + escape(sf.searchterms.value); window.location.href = submitto; return false; } </script> <form name="searchform" onSubmit="return dosearch();"> Select County <select name="sengines"> <option value="http://www2.co.washington.mn.us/opip/mod/addresssrch/result.asp?housenum=&street=" selected>Washington</option> <option value="http://rrinfo.co.ramsey.mn.us/public/characteristic/PropertySearchResults.aspx?pin=&Nbr=&Street=&pg=1" selected>Ramsey</option> <option value="http://www.altavista.com/web/results?q=">Alta Vista</option> <option value="http://www.dogpile.com/info.dogpl/search/web/">Dogpile</option> </select> Street Address: <input type="text" name="searchterms"> <input type="submit" name="SearchSubmit" value="Search"> </form> here is the problem i am running into. I dont know how to ignore or add certain parts of the search when it sends. for example. take a look at Code: <option value="http://rrinfo.co.ramsey.mn.us/public/characteristic/PropertySearchResults.aspx?pin=&Nbr=&Street=&pg=1" selected>Ramsey</option> When i try to do a search under this drop down selection it doesnt work. because it needs the &pg=1 to be added to the users search request. Meaning if I set it to Code: http://rrinfo.co.ramsey.mn.us/public/characteristic/PropertySearchResults.aspx?pin=&Nbr=&Street= they type in their street name and the street name inputs into the search query but it wont fully work because it doesnt add the &pg=1 after it all. how in the world do I get it to add things like that? ie how do i tell it to add certain strings that the outside source requires? like blank=&blank= or how do i get it to ignore certain &blank= commands. another example taking a look at Code: <option value="http://www2.co.washington.mn.us/opip/mod/addresssrch/result.asp?housenum=&street=" selected>Washington</option> this search function should technically be Code: <option value="http://www2.co.washington.mn.us/opip/mod/addresssrch/result.asp?" selected>Washington</option> however since i dont know how to add certain functions to the search i have to skip the housenum option. that means my customers cant search by street number. I want them to be able to type in their house number and their street address and it will change to what each seperate (outside) search engine needs. Does this make any sense at all? Hi, I have a page with an iframe in it. I need my script to search the contents of the iframe for a specified string, and click the link within it. Here is my coding. Code: <script> setTimeout(function() { window.location.reload(); }, 2000); // 2 seconds, e.g. $(document).ready(function() { $('a[href*="13468100"]', $("game").contents()).closest('tr').find('.fightActionInnerInner').parent("a").trigger("click"); }); </script> </head> <body> <iframe src="http://vl.storm8.com/hitlist.php" width="100%" height="800px" id="game"></iframe> In the post below is the content of the iframe. At the moment the script doesn't want to click the link, it just refreshes the page. Can anyone advise? Hi all, Only recently started, self-teaching, html and Java in order to get a project idea of mine up and running. First barrier I've come across is trying to sort out a drop down with search button that will then reveal the connected hidden div, I've mangled together some code from a couple of sources with what I've learnt, but not really sure how to tie in the "Search" button to the showDiv(divname) function. Wondering if anyone could help out. Many thanks in advance Code: <head> <title>Untitled</title> <link rel="stylesheet" type="text/css" href="stylesheet.css" /> <script type="text/javascript"><!-- var lastDiv = ""; function showDiv(divname) { if (lastDiv) { document.getElementById(lastDiv).className = "hiddenDiv"; } if (divName && document.getElementById(divName)) { document.getElementById(divName).className = "visibleDiv"; lastDiv = divName; } } </script> </head> <body> <h1> <form name="form" > <select name="select"> <option selected>Choose <option value="one"> one <option value="two"> two <option value="other"> other </select> <input type="button" value="Search" onClick="showDiv(this.value)"> </form> </h1></br> <h2> Results: <p id="one" class="hiddenDiv">one</p> <p id="two" class="hiddenDiv">two</p> <p id="other" class="hiddenDiv">other</p> </h2> </body> </html> From my stylesheet: Code: .hiddenDiv { display: none; } .visibleDiv { display: block; } Hi Everyone! I have a website that I'm designing where I have the need to search multiple sites at specific times. By this I mean that In some cases, we would want to search only the internet using google, or only search the site that I've created (which currently uses the jse_search.js solution), or only our company's website. I currently have four different search boxes that will search either the internet, the internal site, a separate internal site, or a third-party website, which all working fine. The problem is that the search boxes take up quite a bit of space, and the layout is becoming cumbersome. Is there a way in Javascript I could use a single search box and a drop-down list to select which method to use? The code I'm currently using is below. With the exception of the Google search function, I've modified some of the site names to general site names and paths to preserve the company's anonymity: Code in the <head> tag: Code: <script language="JavaScript1.3" type="text/javascript" src="jse_form.js"> </script> Code in the <body> tag: Code: <!--Begin Internal Site Search 1!--> <div> <p style="text-align: center;"> <table border="0" cellpadding="0"> <tr><td><form name="jse_Form" onsubmit="search_form(jse_Form);return false"> <input type="text" name="d" size="30"> </tr></td> <tr><td> <input type="button" value="Internal Site Search 1" onclick="search_form(jse_Form)"> </form> </tr></td> </table> <!--End Internal Site Search 1!--> <!--Begin Internal Site Search 2!--> <div> <p style="text-align: center;"> <table border="0" cellpadding="0"> <tr><td> <!--webbot bot="Search" S-Index="all" S-Fields S-Text="Search for:" I-Size="20" S-Submit="Start Search" S-Clear="Reset" S-TimestampFormat="%m/%d/%Y" TAG="BODY" b-useindexserver="1" startspan --> <form action="http://sitesearch2.idq" method="POST"><input type="text" name="UserRestriction" size="30" value> </tr></td> <tr><td style="text-align: center;"> <input type="submit" value="Internal Site Search 2"></form> </form> <!--webbot bot="Search" i-checksum="4210" endspan --> </td></tr> </table> </div> <!--End Internal Site Search!--> <!--Begin Google Search!--> <form method="get" action="http://www.google.com/search"> <div> <p style="text-align: center;"> <table border="0" cellpadding="0"> <tr><td> <input type="text" name="q" size="30" maxlength="233" value="" /> </tr></td> <tr><td align="center"> <input type="submit" value="Google Search" /></td></tr> </table> </div> </form> <!--End Google Search!--> <!--Begin Third Party Search!--> <form id="keywordSearchForm" method="get" action="http://www.site3.html"> <div> <p style="text-align: center;"> <table border="0" cellpadding="0"> <tr><td> <input class="input" type="text" name="keyword" size="30" /> </tr></td> <tr><td align="center"> <input type="hidden" name="origin" value="keywordsearch" /><input id="go" class="button" tabindex="0" type="submit" value="Third Party Search" /> </td></tr> </table> </div> </form> <!--End Third Party Site Search!--> Hi experts, is it possible via Javascript to search certain websites with certain keywords without having to use specific search engines? example search only the following: 1. www.yyy.com 2. www.aaa.com 3. www.zzz.com for the keyword "Laminat" and open the sites accordingly. thx I'd like to create two dropdown (select) lists with a search button next to it so if the user chooses A in the first list and C in the second list and clicks 'search', the results return items that relate to both A and C. Practical Example: User chooses "London" in the first dropdown and "Middle Schools" in the second. Result returns the middle schools I've listed for London. How can this be done or if it can't, is there another way to achieve what I want? -edit- I found what I wanted he http://www.alistapart.com/d/complexd...ts&de=Pancakes However, now my question is what would I put in for the form "action" to populate the results? Ok so im new to javascript and I have a button in an interface for an app. It's like drag and drop and i want this button to link you to a certain website searching for what the user types in the searchField1 box. The button is button16. Such as you type dogs into the text box and you click the google button among other search engines and it will redirect you to a google search doing a search for dogs. But how do I make this button search google and search for whats in searchField1. I would really appreciate the help. Im looking everywhere to learn this but just cant find it. If you could tell me how or send me a link to a tutorial that would be great. Thanks! Here is the code: I don't know where and what to add to do that. Please help. Hello people. I'm looking to create a simple search engine capable of searching multiple search engines simultaneously together (e.g. Google, Bing, Yahoo, etc.) and then displaying the results below for all sites on the same page. I don't want each search engine results page opening up in individual windows or anything, nor do I want people to have to manually select the search engine to search with. Just a single page where a user types in something, pressed [Enter] and then presented with all results from multiple sites on one page (without duplicates). I'm also looking to do this with image and torrent sites, etc. How would I go about doing this? Thanks a million guys. You have bigger brains than me. I want to append a string "&sid=xyz" to the current page URL if the referring URL comes from site www.xyz.com. I have the following code - var query = location.search.substring(1); if (document.referrer.indexOf(/xyz/) > 0) { query = query + "&sid=xyz"; } However, the string is not being appended. Can anyone see where the problem lies? hello, I'm trying to build a simple function to append and replace an argument in a query string, for example, if my url was like; www.domain.com/page.php?test=123&blah=abc and I want to add on qty=5 like; www.domain.com/page.php?test=123&blah=abc&qty=5 ok, no problem there, however if I now want to update that to qty=6, i get this: http://www.domain.com/page.php?test=...bc&qty=5&qty=6 my code thus far; Code: function AppendURL(){ var AURL = document.getElementById('AddToCartLink'); var numQty = document.getElementById('Qty').value; var TempURL = AURL.href; AURL.href = TempURL + '&Qty=' + numQty; } Here is the link in question. I have created a small page with the isolated problem on it. http://frontendaudio.com/v/vspfiles/...pt_tester.html the javascript file that is referenced basically only does one thing. It searches for "> >" and then alerts us whether or not it's on the page. --- It pulls the innerHTML of the entire document --- the searches it - and indexes the string. I echoed the string out to a text area so you could see the string "> >" is clearly there after the word microphones in the link tag... </a> > < etc.. Any thoughts on how I can detect this string somehow? Thanks. Here is the code inside the javascript file. Code: var myStringDiscuss = 'microphones</a> >'; myStringDiscuss = myStringDiscuss.replace(/~/g,""); // unmunge function discussDetection(){ var str = document.getElementsByTagName('html')[0].innerHTML; str = str.toLowerCase(); // to make case insensitive var category_string = str.indexOf(myStringDiscuss); if (category_string == -1) { alert("not on this page"); } else { alert("IS on the page"); } } window.onload= discussDetection; I need to use javascript in a way in which it will keep clicking a button. The source code for that button is below: Code: <script type="text/javascript"> function set_opacity(id, opacity) { element = document.getElementById(id) if (/MSIE/i.test(navigator.userAgent)) { element.style.filter='alpha(opacity='+opacity+')'; } else { element.style.opacity = opacity/100; } } </script> <div class="recruiter_enabled"> <table cellspacing="0" style="width: 100%"> <tr> <td> <p> <script type="text/javascript"> //<![CDATA[ recruiter_clicks = 1 //]]> </script><a href="/recruiter/recruit/3p5tjd4pdnbg0" id="recruit_link" onclick="return(submit_link_as_post_with_opacity(this, 'recruit_image'))"><img alt="" class="start_recruiting" id="recruit_image" src="/A.gif?1221518016" /></a><script type="text/javascript"> //<![CDATA[ link = document.getElementById('recruit_link'); link_href = link.href; link.href = "#"; set_opacity('recruit_image', 50); setTimeout("link = document.getElementById('recruit_link'); link.href = '" + link_href + "'; recruiter_clicks = 0; set_opacity('recruit_image', 100)", 2000); //]]> </script> Therefore, I need javascript to keep clicking the button until it has clicked it 375 times. How would I be able to do this? |