JavaScript - Search For '*' In A String
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?
Similar TutorialsIn 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()? 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. 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 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? 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. 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. 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; Hey all, I have a simple example below showing how when I pass in the value of the value attribute of option node, and then use if operator to check whether parameter is a string or not, even though it's a string, it converts it to false boolean and triggers the else statement rather than calling a function: Code: <body> <select> <option value="createMsg">Add Message</option> <option value="removeMsg">Remove Message</option> </select> </body> Code: var menu = { handleMenu : function(callback){ if(callback === "string"){ menu[callback](); } else { console.log("Issue occurred") } }, createMsg : function(){ var content = document.createTextNode("Please give additional information."), heading = document.createElement("h1"); heading.appendChild(content); document.body.appendChild(heading); }, removeMsg : function(){ } } document.getElementsByTagName('select')[0].onchange = function(){ menu.handleMenu(this.value)}; callback should be a string so why is it saying otherwise? Thanks for response 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 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 am trying to use some string functions with no results. It appear what I'm using them on are not strings. my_string = document.getElementById("link5").onclick; document.write(my_string.lastIndexOf("5")); This gets nothing! And document.write(document.getElementById("link5").onclick.lastIndexOf("5")); gets nothing. BUT if I make a string and put what the onclick is set to with: my_string = "function onclick(event) { reveal(\"5\", \"2\", \"1864\")"; then my_string.lastIndexOf("5") will yield 34. So why is my original my_string = not working? And how can I get it to work? I was looking at this page, and came across "%" used in strange context. It appears that the mod operator can be used in Strings?? http://download.oracle.com/javase/tu...vaOO/enum.html What does this do/ mean? Thanks!!: System.out.printf("Your weight on %s is %f%n", p, p.surfaceWeight(mass)); This is probably easy if I knew Javascript. Can someone show me the code to get the number "800014352" part from the url???? http://testebiz/ebizbtest/ShoppingCa...2/Default.aspx I need help with the following code below. It just doesn't turn out okay. Any ideas? Code: function changing() { A = document.exempel.Amount.value B = ("<%#Container.DataItem("Price_2_qty")%>") C = ("<%#Container.DataItem("Price_3_qty")%>") D = ("<%#Container.DataItem("Price_4_qty")%>") E = ("<%#Container.DataItem("Price_5_qty")%>") if (A < B) {document.exempel.Price.value = "<%#Container.DataItem("Price_1")%>"} else if (A = B && (!(A >= C))) {document.exempel.Price.value = "<%#Container.DataItem("Price_2")%>"} else if (A = C && (!(A >= D))) {document.exempel.Price.value = "<%#Container.DataItem("Price_3")%>"} else if (A = D && (!(A >= E))) {document.exempel.Price.value = "<%#Container.DataItem("Price_4")%>"} else if (A >= E) {document.exempel.Price.value = "<%#Container.DataItem("Price_5")%>"} } This is all php except for the java code I am struggling with. Please advise. I have tried this 2 ways and have spent hours on something that should be simple. I have a string that I am trying to display in an alert box with an onclick method 1: $mystring = "<a href=\"mysite.com\">Click</a>"; this does not work echo "<input type='button' value='Grab Code' onClick=alert('$mystring')>"; nor does this echo "<input type='button' value='Grab Code' onClick=alert('".$mystring."')>"; nor does anything I try. All I want to do is display the value of mystring in an alert box. However, this does work .. echo "<script type='text/javascript'> alert('".$mystring."');</script>"; But I cannot call this from an onclick. Any help is appreciated. Thanks JT Hi, I'm working on refining my search function. At the moment it works fine like this: Code: function searchLocations() { var found = false; var input = document.getElementById('autocomplete').value; for (var j = 0; j < gmarkers.length; j++) { if (gmarkers[j].myname.toLowerCase() == input.toLowerCase()) { found = true; gmarkers[j].show(); myclick(j); } } if ( ! found ) alert("No matches found. Please check your spelling or refine your search."); } but you have to get the input exactly the same as it is in the array for it to work (as it should, being that that's the way it's written). I wanted to split it so that for example Black Cat Hotel would pop if the user entered Black OR Cat OR Hotel (or any combination of the above). So I thought that this might work: Code: function searchLocations() { var found = false; var input = document.getElementById('autocomplete').value; for (var j = 0; j < gmarkers.length; j++) { var s = gmarkers[j].myname.toLowerCase().split(" "); if ( s == input.toLowerCase()) { found = true; gmarkers[j].show(); myclick(j); } } if ( ! found ) alert("No matches found. Please check your spelling or refine your search."); } but obviously not. Is there some better way to do this? Help, I can't figure out why this doesn't work. Thanks.. [CODE] 1 //==UserScript== 2 // @name Add youcalc highrise tab 3 // @namespace http://www.youcalc.com/ 4 // @include http://*.highrisehq.com/* 5 // @include https://*.highrisehq.com/* 6 // @exclude http://www.highrisehq.com/* 7 // @exclude http://forum.highrisehq.com/* 8 // @exclude https://www.highrisehq.com/* 9 // ==/UserScript== 10 11 //change to your needs 12 13 appurl1 = "http://www.youcalc.com/pubapps/1232017802730/"; 14 tabtitle1 = "Deals and forecast"; 15 appwidth1 = "830px"; 16 appheight1 = "690px"; 17 18 appurl2 = "http://www.youcalc.com/pubapps/1226931095311/"; 19 tabtitle2 = "Deals Activity Report"; 20 appwidth2 = "830px"; 21 appheight2 = "690px"; 22 23 appurl3 = "http://www.youcalc.com/pubapps/1229432659119/"; 24 tabtitle3 = "Contacts By Tag"; 25 appwidth3 = "830px"; 26 appheight3 = "690px"; 27 28 //from here, change at own risk 29 tabs = document.getElementById('Tabs'); 30 tabshtml = tabs.innerHTML; 31 32 //new tab html and JS 33 youcalcapp1 = '<iframe src=' + appurl1 + ' width=' + appwidth1 + ' height=' + appheight1 + ' style=border:none; />'; 34 youcalcapp2 = '<iframe src=' + appurl2 + ' width=' + appwidth2 + ' height=' + appheight2 + ' style=border:none; />'; 35 youcalcapp3 = '<iframe src=' + appurl3 + ' width=' + appwidth3 + ' height=' + appheight3 + ' style=border:none; />'; 36 37 putyoucalc1 = "inner_body = document.getElementById('screen_body');inner_body.innerHTML = '"+ youcalcapp1 + "';yct1 = document.getElementById('youcalctab1');yct1.className='current';yct2 = document.getElementById('youcalctab2');yct2.className='';";yct3 = document.getElementById('youcalctab3');yct3.className='';"; =========================================================^ SyntaxError: unterminated string literal 38 putyoucalc2 = "inner_body = document.getElementById('screen_body');inner_body.innerHTML = '"+ youcalcapp2 + "';yct2 = document.getElementById('youcalctab2');yct2.className='current';yct3 = document.getElementById('youcalctab3');yct3.className='';";yct1 = document.getElementById('youcalctab1');yct1.className='';"; 39 putyoucalc3 = "inner_body = document.getElementById('screen_body');inner_body.innerHTML = '"+ youcalcapp3 + "';yct3 = document.getElementById('youcalctab3');yct3.className='current';yct2 = document.getElementById('youcalctab2');yct2.className='';";yct1 = document.getElementById('youcalctab1');yct1.className='';"; 40 41 //find last tab, and put youcalc tab after 42 lasttab = 'Tags</a></li>'; 43 youcalctabs = '<li class="with_space" ><a class="" id="youcalctab1" onclick="' + putyoucalc1 + '" href="#">' + tabtitle1 + '</a></li><li class="with_space" ><a class="" id="youcalctab2" onclick="' + putyoucalc2 + '" href="#">' + tabtitle2 + '</a></li>';<li class="with_space" ><a class="" id="youcalctab3" onclick="' + putyoucalc3 + '" href="#">' + tabtitle3 + '</a></li>'; 44 tabshtml = tabshtml.replace(lasttab,lasttab+youcalctabs); 45 tabs.innerHTML = tabshtml; I'm trying to determine whether a word exists in the URL and if so, change the CSS of a div. I know how to do each task individually, but combining the two is giving me trouble. So far I have: Code: function checkSent(divname) { if(document.URL.indexOf("sent") >= 0) *document.getElementById(success).style.display = 'block'; } var sentornot = checkSent(); // If the URL contains the word, sent, then change the display of the element "success" to block I can successfully determine whether the string exists in the URL by adding an alert, but the Javascript to change the CSS doesn't work. The CSS for the div element "success" is as follows: Code: #success { display: none; } Any help is appreciated! Thanks! Edit: If needed, this is the code I used to test whether the "check URL" portion works: Code: function checkSent(divname) { if(document.URL.indexOf("sent") >= 0) { alert("found"); document.getElementById("success").style.display = 'block'; //this line doesn't work :( } else{ alert("not found"); } } Hello, I need your help. Let's say for example if I have the following file number: 2011-1234567 and if the value of the variable is already the same (ie. var fileNo = 2011-1234567) how can I go about automatically adding a number at the end? ex.1.) var fileNo = "2011-1234567" if (fileNo already exists) { fileNo = 2011-1234567-2 } ex.2.) var fileNo = "2011-1234567-2" if (fileNo already exists) { fileNo = 2011-1234567-3 } ect. Much thanks and appreciation for all your help. Jay |