JavaScript - Javascript Query String
Hi I am trying to create a query string similar to the one available he http://andrewu.co.uk/tools/request/e.../example1.html
The problem that I am having is that I have more than one button on my page and even though my id's are unique all of my data is displaying on the action page at the same time. The code that i am using for my buttons is: Code: <label for="name_1">Name:</label> <input type="text" name="name1" id="name_1" tabindex="1" size="40" value="Donald Duck" /> <br /> <br /> <input type="submit" id='view1' value="Submit" tabindex="2" /> <label for="name_1">Name:</label> <input type="text" name="name2" id="name_2" tabindex="1" size="40" value="Mickey Mouse" /> <br /> <br /> <input type="submit" id='view2' value="View" tabindex="2" /> I have a lot more than 2 buttons on my page. when a button is clicked I would like to be able to get the values from the query string and only see the values for the button that was clicked like this one: http://andrewu.co.uk/tools/request/e...ndrew+Urquhart but instead I am getting Name: Donald Duck, Name: Mickey Mouse. What would I have to add or change to obtain just one Name to display at a time but have it be different depending on which button is pressed? 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 Hello everybody ! I'm searching for a javascript function that convert array to query string. Like this example : Code: var array = { a=1, b=2, c=3 }; to a=1&b=2&c=3 I'm using jQuery and the function .serialize() convert only html forms. Does someone know a function to do this ? Thanks ! Hello all, essentially i am grabbing a variable from the query string and i need to pass that value into another script. allow me to explain; usually i use this code to display a persons email address from the query string onto the page using document.write <script> function getQueryVariable(variable) { var query = window.location.search.substring(1); var vars = query.split("&"); for (var i=0;i<vars.length;i++) { var pair = vars[i].split("="); if (pair[0] == variable) { return pair[1]; } } document.write(''); } </script> then i would display the var with this <script> document.write( getQueryVariable("Contact0Email") ); </script> ------------ ok so here is what i need to do. my client sent me the code below asking me to pass the email var into the javascript and image. my programmer friend said to use php and do smething like; <SCRIPT language="javascript" src="https://www.cpctrack.com/redirconsume.aspx?CID=25240&ORDERID=<? echo . $_GET['Contact0Email']; ?>"></SCRIPT> <NOSCRIPT><IMG src="https://www.cpctrack.com/redirconsume.aspx?CID=25240&p=img&ORDERID=<? echo . $_GET['Contact0Email']; ?>" width="1" height="1" border="0"></NOSCRIPT> this syntax does not work; <? echo . $_GET['Contact0Email']; ?> WHAT DO YOU GUYS THINK? Is the syntax wrong or are there better methods? Hey all, I have an issue building a query string. Basically, I have this: /sites?order=site_numper_page=20& But I would like to convert it to this: /sites?order=site_num&per_page=20 I have tried this to check if the current iterator is less than the length of the object and if so, then add the "&", otherwise, don't. But it doesn't seem to work: Code: $.each(query_string, function(key,value){ params += key + '=' + value; if((value + 1) != query_string.length){ params += "&"; } }) Thanks for any response. Hi all, I would really appreciate it if someone could help me with this problem. I have some JavaScript code that encodes (escapes) a string (typically a URL) - I then want to pass the encoded string to a php page via a querystring. Trouble is, the querystring doesn't contain the correct encoded string! For example - If we assume the string I want to pass contains the data : tester My encoder, encodes this as : %74%65%73%74%65%72 When the code then passes this in a query string to, for example, code.php the querystring comes out as follows : code.php?encstring=tester The following is the JavaScript code that encodes, shows an alert box with the correct encoded string in it and then calls the code.php with the encoded string attached. Please help? What am I missing here? Code: NOTE: variables: os is the input string and ns is the encoded string. Code: <script type="text/javascript"> var os='tester'; var ns=''; var t; var chr=''; var cc=''; var tn=''; for(i=0;i<256;i++){ tn=i.toString(16); if(tn.length<2)tn="0"+tn; cc+=tn; chr+=unescape('%'+tn); } cc=cc.toUpperCase(); os.replace(String.fromCharCode(13)+'',"%13"); for(q=0;q<os.length;q++){ t=os.substr(q,1); for(i=0;i<chr.length;i++){ if(t==chr.substr(i,1)){ t=t.replace(chr.substr(i,1),"%"+cc.substr(i*2,2)); i=chr.length; }} ns+=t; } alert(ns); window.location = "code.php?encstring="+ns; </script> Code: <head> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script> <script> function getQuerystringNameValue(subid) { var winURL = window.location.href; var queryStringArray = winURL.split("?"); var queryStringParamArray = queryStringArray[1].split("&"); var nameValue = null; for ( var i=0; i<queryStringParamArray.length; i++ ) { queryStringNameValueArray = queryStringParamArray[i].split("="); if ( subid == queryStringNameValueArray[0] ) { nameValue = queryStringNameValueArray[1]; } } return nameValue; } </script> <script> function getQuerystringNameValue(uid) { var winURL = window.location.href; var queryStringArray = winURL.split("?"); var queryStringParamArray = queryStringArray[1].split("&"); var nameValue = null; for ( var i=0; i<queryStringParamArray.length; i++ ) { queryStringNameValueArray = queryStringParamArray[i].split("="); if ( uid == queryStringNameValueArray[0] ) { nameValue = queryStringNameValueArray[1]; } } return nameValue; } </head> And trying to pass into this link but its not working. Code: <map name="Map"> <area id="link-connector" shape="rect" coords="33,466,349,530" href="http://www.linkconnector.com/ta.php?lc=125601055059003882&atid=" + getQuerystringNameValue("uid") + "&ptid=" + getQuerystringNameValue("subid") + "&lcpt=0&lcpf=3"> </map> <body> Reply With Quote 01-13-2015, 07:21 PM #2 rnd me View Profile View Forum Posts Visit Homepage Senior Coder Join Date Jun 2007 Location Urbana Posts 4,497 Thanks 11 Thanked 603 Times in 583 Posts you can't use script in the middle of an attrib like that, you need to hard-code that url in whole, or build the string in JS and apply it all at once. Hello Friends... I am working on parsing the querystring using javascript So I have successfully parsed the querystring & also replace the special character+ but I want to display the querystring in the TextField Control So how to implement it Please guide me.... Hey I need help to obtain the requested javascript's query string. Example: Code: <script type="text/javascript" src="script.js?v=123"></script> How can I use that query string inside script.js for example like Code: var v = 'The code to get the query fragment'; alert(v); // alerts '123' Thank you. - DJCMBear Hello, I am trying to update an iframe when the user makes a selection from a select box. I don't have any trouble with changing the iframe, but when I try to send a varible as a quey string, the variable doesn't pass to the iframe properly. // this is in my header, and it is initiated from the onchange below. // it changes the page fine, but doesn't read the varible "num" // that was passed to the function <script language="javaScript"> <!-- function updatenotes (num) { document.getElementById("desc").src = 'iframe1.cfm?dec=num' } //--> </script> // this is the select box that initiates the function from onchange // for simplicities sake, I hard coded 3 options, but in reality, // these options are ever changing <select name="Description" onchange="updatenotes(this.options[selectedIndex].value)"> <option name="">Select a project</option> <option name="2" >project2</option> <option name="3" >project3</option> </select> Any help you can offer would me ver appreciated. thanks 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. 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()? How to handle String in Javascript
Hello, I have the following Javascript function: Code: function loadReviews(){ var url='http://search.twitter.com/search.json?callback=?&q=test'; jQuery.getJSON(url,function(json){ jQuery.each(json.results,function(i,review){ jQuery("#divroller_container").append('<div class="reviews" id=item'+i+'>'+review.text+'<br>Reviewed By: '+review.from_user+'</div>'); }); start(30000, 1); }); } I'm trying to use this in a PHP page. I tried to make do an echo ' and then display the Javascript but I'm struggling on how to convert the following line to PHP to that it still works like it should in Javascript: Code: jQuery("#divroller_container").append('<div class="reviews" id=item'+i+'>'+review.text+'<br>Reviewed By: '+review.from_user+'</div>'); I still need the Javascript variables to function the same etc. Any help would be greatly appreciated. Thanks in advance! string check in javascript do suggest me something ....... if you have any two words like , "me" and "you". I have an input box with an I.D. of "q" on my website... By entering javascript into the URL bar I can change the place holder text (client side) to say "test" javascript:void(document.getElementById('q').value='test'); Now if I wanted to make it say test (but in bold with html) how would I do that?? I tried: javascript:void(document.getElementById('q').value='<b>test'); But that won't work.. it's a string! I don't know much javascript... Thanks all! Hey, Im using Google Maps and when the user moves the map I have an event listener to return a string of routeIDs that are within the bounds of the map. Later on in the page I have a PHP MySQL statement where it Has [ICODE] SELECT * FROM routes WHERE [ICODE] , and after the WHERE I want to add this string. Basically as the user moves the map around, the list of available routes in bounds should change. How can I do this without redirecting pages at all, as that destroys the functionality of the google map? A typical return of the string would be [ICODE] id = 32 OR id = 58 OR id = 70 [ICODE] etc Any ideas? Thanks all, Rick I am throughly confused....why does this seemingly simple deal not work? Code: <script type="text/javascript"> <!-- window.onbeforeunload = function (){ var checkboxImg = new Image(); var checkboxImgUrl = "checkbox.php%3Flonger%3D" + reviews-chk-longer.checked + "%26discrete%3D" + reviews-chk-discrete.checked + "%26natural%3D" + reviews-chk-natural.checked + "%26thicker%3D" + reviews-chk-thicker.checked + "%26permanent%3D" + reviews-chk-permanent.checked + "%26stamina%3D" + reviews-chk-stamina.checked + "%26harder%3D" + reviews-chk-harder.checked + "%26vascularity%3D" + reviews-chk-vascularity.checked + "%26drive%3D" + reviews-chk-drive.checked + "%26guarantee%3D" + reviews-chk-guarantee.checked + "%26trials%3D" + reviews-chk-trials.checked + "%26affordable%3D" + reviews-chk-affordable.checked; alert(checkboxImgUrl); checkboxImg.src = checkboxImgUrl; } // --> </script> I get no alert when I do this....however the same thing without all of the added strings works fine, ie: Code: <script type="text/javascript"> <!-- window.onbeforeunload = function (){ var checkboxImg = new Image(); var checkboxImgUrl = "checkbox.php"; alert(checkboxImgUrl); checkboxImg.src = checkboxImgUrl; } // --> </script> Can anyone please help? I tried using .concat and that didn't help either Hi all, can anyone tell me why the connection string for the jscript doesn't work but vbscript does? I'm using IE7 only. ------------------------------------ Code Start ----------------------------- <html> <head> <title></title> <script language="vbscript"> Sub GetVBscriptData() Set oADOCon = CreateObject("ADODB.Connection") Set oRecSet = Createobject("ADODB.recordset") oADOCon.ConnectionString = "Provider=SQLOLEDB;Server=PIBDKM894\SQLEXPRESS;Database=SOEAudit;Uid=SOEAuditAdmin;Pwd=password" oADOCon.Open oRecSet.Open "SELECT * FROM Customers", oADOCon sList = "" Do Until oRecSet.EOF sList = sList & oRecSet("NewFirstName") & vbCrLf oRecSet.MoveNext Loop MsgBox sList End Sub </script> <script language="javascript"> function GetJScriptData() { var oADOCon = new ActiveXObject("ADODB.Connection"); var oRecSet = new ActiveXObject("ADODB.Recordset"); var ConnectionString = "Provider=SQLOLEDB;Server=PIBDKM894\SQLEXPRESS;Database=SOEAudit;Uid=SOEAuditAdmin;Pwd=password" ; oADOCon.Open(ConnectionString); oRecSet.Open("SELECT * FROM Customers",oADOCon); var sList = ""; while (!oRecSet.EOF){ sList = sList + oRecSet("NewFirstName"); oRecSet.MoveNext(); } alert(sList); } </script> </head> <body> <input type="button" onclick="GetVBscriptData()" value=" Get some data via vbscript"> <input type="button" onclick="GetJScriptData()" value=" Get some data via javascript"> </body> </html> ------------------------------------- Code End ------------------------------ The error I receive is: Message: [DBNETLIB][ConnectionOpen (Connect()).]SQL Server does not exist or access denied. Line: 26 (opening the javascript connection) I can only presume it's the syntax of the connection string. Any ideas how to alter the string to get it connecting? Thanks in advance, t-racer |