JavaScript - Displaying The Query String In The Textfield
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.... Similar TutorialsHello 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. 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 ! 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? 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 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. 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> 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 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()? Hey folks, I have a little problem here, I have two textfield and a botton Text fields: Code: <input name="rate" type="hidden" id="rate" value="<%= rs_rating.Fields.Item("rate").Value %>" /> <input name="plus" type="hidden" id="plus" value="1" /> <input name="total" type="hidden" id="total" /> <input type="Submit" name="Submit" id="Submit" value="Course Rating " /> Now what I want is something like this input "rate" value + input "plus" value which means if for example if rate (with dynamic value which could be any number) is 4 it will be 4+1 (1 is the static value of input "plus") which will be 5 and that 5 would be the value of input "total" that is the only text field which submit to DB. Just need the JS for that math problem. Thanks folks. anyone would you help me I have some problem to calculate PHP Code: <table width="415" cellspacing="1" cellpadding="1"> <tr> <th width="151" scope="col">Price</th> <th width="189" scope="col">qty</th> <th width="63" scope="col">total</th> </tr> <tr> <td><label> <input name="price" type="text" id="price" value="2000"> </label></td> <td><label> <input name="qty" type="text" id="qty" value="2"> </label></td> <td><label> <input name="total" type="text" id="total" value="4000"> </label></td> </tr> <tr> <td><input name="price" type="text" id="price" value="2000"></td> <td><input name="qty" type="text" id="qty" value="4"></td> <td><input name="total" type="text" id="total" value="8000"></td> </tr> <tr> <td> </td> <td>Total</td> <td><label> <input name="gtotal" type="text" id="gtotal" value="12000"> </label></td> </tr> </table> How to calucate it from price * qty = Total and gtotal=sum of total, in the first rows. Ican do it if there is one row, but i dont know how to calculate samae name of text field like in 2nd or more rows Hello, I am fairly new to javascript and am having trouble clearing a text field. I am making a "vending machine simulator" as an exercise. I have a button that is the coin return, and should clear the balance display. e.g the machine shows a balance of $2 inserted, the coin return button should clear it to 0. I believe I have done everything correctly but get NaN as the output (a text field named "box1"). I believe it has something to do with how the field is validated. It has number precision set to 2, which I would think would just become 0.00 or something. Anyways, here is my code: HTML: Code: <input class="money" id="coinreturn" type="button" value="return" onClick="coinReturn()" /> <input name="box1" id="box1" onkeypress="return numbersonly(this, event)" maxlength="4" type="text"/> JavaScript for the coinReturn function: Code: function coinReturn() { document.getElementById('box1').value = 0; } JavaScript for the "numbers only" validation: Code: function numbersonly(myfield, e, dec) { var key; var keychar; if (window.event) { key = window.event.keyCode; } else if (e) { key = e.which; } else { return true; } keychar = String.fromCharCode(key); // control keys if ((key==null) || (key==0) || (key==8) || (key==9) || (key==13) || (key==27) ) { return true; } // numbers else if ((("0123456789.").indexOf(keychar) > -1)) { return true; } } Hi all. I have a textfield on my form problem. My boss wants it as a textfield to keep the field small on the page but still wants to be able to read all of the information that is in the field. What can I do with this?? Can we have change to textarea when he hovers to clicks in it. Any help would be appreciated. Hello, I'm looking to create a web form with various text field to get input from users. Upon enter data to each field, users should have option to genenrate another text field underneath (i.e. a sub criteria of the above field). This is what i have so far, but i cannot get each button to generate the textfield right underneath. Here's my code: <html> <head> <title>test</title> <script> var maxFieldWidth = "500"; function addRow(element, indentFlag) { var elementClassName = element.className; // this is the class name of the button that was clicked var fieldNumber = elementClassName.substr(3, elementClassName.length); // current textfield width, take off the px on the end var fieldWidth = document.getElementById("textfield" + fieldNumber).style.width; fieldWidth = fieldWidth.substr(0, fieldWidth.indexOf("px")); // get the new field number (incremented) var newFieldNumber = ++fieldNumber; // get new field width in case we are indenting var newFieldWidth = fieldWidth; if(indentFlag) newFieldWidth = fieldWidth - (newFieldNumber * 10); var rowContainer = element.parentNode; // get the surrounding div so we can add new elements // create text field var textfield = document.createElement("input"); textfield.type = "text"; textfield.setAttribute("value", "textfield " + newFieldNumber); textfield.id = "textfield" + newFieldNumber; textfield.setAttribute("style","width:" + newFieldWidth + "px; margin-left: " + (maxFieldWidth - newFieldWidth)); // create buttons var button1 = document.createElement("input"); button1.type = "button"; button1.setAttribute("value", "++"); button1.setAttribute("onclick", "addRow(this, false)"); button1.className = "row" + newFieldNumber; var button2 = document.createElement("input"); button2.type = "button"; button2.setAttribute("value", "+"); button2.setAttribute("onclick", "addRow(this, true)"); button2.className = "row" + newFieldNumber; var button3 = document.createElement("input"); button3.type = "button"; button3.setAttribute("value", "-"); button3.className = "row" + newFieldNumber; // add elements to page rowContainer.appendChild(document.createElement("BR")); // add line break rowContainer.appendChild(textfield); rowContainer.appendChild(document.createTextNode(" ")); // add space rowContainer.appendChild(button1); rowContainer.appendChild(document.createTextNode(" ")); // add space rowContainer.appendChild(button2); rowContainer.appendChild(document.createTextNode(" ")); // add space rowContainer.appendChild(button3); } </script> </head> <body> <div id="main-container"> <div> <input type="text" id="textfield1" value="textfield 1" style="width:500px;" /> <input type="button" class="row1" value="++" onclick="addRow(this, false)"> <input type="button" class="row1" value="+" onclick="addRow(this, true)"> <input type="button" class="row1" value="-"> </div> </div> </body> </html> Hi, I have a text field on which I am writing onChange event. The value of text field is getting changed by calander popup by selecting date from calander, but onChange event is not fired unless I manually change the text field, how can we force the event to fire when date is selected by calander popup. any hints please...?? here is my onchange code Code: <input type="text" onChange="changeFinishDates(this.value, this.name)" id="statusFinishDate<%=currModule%><%=bomGroupName%>" name="statusFinishDate<%=currModule%><%=bomGroupName%>" value="<%=statusFinishDateYYYY%>" class="input_med" maxlength="10" title="Enter Promise Date in MM/DD/YYYY format"> <a href="#" onClick="javascript:calPrmdate.select(Status_Dates.statusFinishDate<%=currModule%><%=bomGroupName%>,'anchorPrmdate','MM/dd/yyyy'); return false;" name="anchorPrmdate" id="anchorPrmdate">select</a> <input type="hidden" value="<%=bomGroupName%>" name="bomGrp<%=currModule%>" id = "bomGrp<%=currModule%>" /> Hey Forum, I have this little script working great when all if's are seperated. what i need is to have the script read if one of these fields has a value then result=true. as you see the script now i have this seperated in many different if's for all three text fields. I need to put all text fields like they were one, thanks Code: function ValidateLink(Form) { var result = true; if (formMyLocations.cellAddress.value.length == 0) { alert('Cell address is empty on the locations page'); result = false; } if (formMyLocations.homeAddress.value.length == 0) { alert('Home address is empty on the locations page'); result = false; } if (formMyLocations.carAddress.value.length == 0) { alert('Car address is empty on the locations page'); result = false; } return result; } Hi, The following code tests the 'numbers' field for numbers. It generates an alert if the field contains anything but numbers. Code: <script type='text/javascript'> function isNumeric(elem, helperMsg){ var numericExpression = /^[0-9]+$/; if(elem.value.match(numericExpression)){ return true; }else{ alert(helperMsg); elem.focus(); return false; } } </script> <form> Numbers Only: <input type='text' id='numbers'/> <input type='button' onclick="isNumeric(document.getElementById('numbers'), 'Numbers Only Please')" value='Check Field' /> </form> However, if I want to change the above statement to read if the textfield does not equal to a number, return true, else, alert the user and return false. I change the branch statement and have it read "if(!(elem.value.match(numericExpression)))," to try to do this. But, the alert message does not generate if I enter "abc123" even though that value clearly contains numbers. Not sure what is going here. Please help me. Thank you. |