JavaScript - Removing Unwanted Characters From A Passed Value And Passing To Input Field
My java skill are rudimentary at best.
I have an email which has some values attached to a link in the email that get passed to an online form on a website when clicked. Problem is the value is a price and the string includes a "$" which I need to remove. I've read through many examples and everyone seems to have an opinion (surprise). One suggests something like this: Code: text2.value=text1.value.replace(/\$/g,""); While someone else says its better to remove what you don't want. I am also scratching my head over should I place the value into a hidden field, scrub it then copy that into the proper field? and I imagine the best way would be to run it with an "onload" command instead or a event handler like a keystroke since the field is not typed? Roundtable discussion would be appreciated to help me solve this simple problem and help expand my knowledge of java... thanks. Similar TutorialsHi, So I've got an array called questions_raw Code: questions raw = [ ["<Q1> Question", "choice1","choice2", "choice3"], ["<Q2> Question", "choice1","choice2", "choice3"], ... ] And I want to list all of the questions, but not the choices/answers. So far, I've managed to list just the questions, but because another function randomly sorts them, I need to sort them back into numerical order for a separate function (displaying the questions) I use characters (>,^) at the front to separate them into different answer types (just to explain the code) I try this to cut each string down so that they can be sorted numerically/alphebetically - Code: function linearlist() { var list = []; var tempStr = ""; for (var l = 0; l < 145; l++) { tempStr = questions_raw[l][0]; list[l] = tempStr; } if (list.charAt(0)== " " ) list = list.substring(3) ; if (list.charAt(0)== ">" ) list = list.substring(3) ; if (list.charAt(0)== "^" ) list = list.substring(3) ; var sorted = list.sort(); document.Qtext2form.Qtext2.value = sorted.join("\n"); } But it doesn't like it - because "it has no method charAt" Any idea what i'm missing? Is it just that you have to put the [l] in every time you call a variable? Cheers Hi. I'm trying to get my script below working. I've managed to get it to add fields dynamically but the remove function isn't right... and I can't think of a way round it. any ideas? also.. how can i incorporate a way for a limit on the number of fields that can be added? cheers! any help would be very appreciated. Code: <script type="text/javascript"> function addInput() { var x = document.getElementById("inputs"); x.innerHTML += "<input type=\"text\" />"; } function removeInput() { var x = document.getElementById("inputs"); x.innerHTML -= "<input type=\"text\" />"; } </script> <input type="button" value="add field" onclick="addInput();" /> <input type="button" value="remove field" onclick="removeInput();" /> <div id="inputs"></div> .. update: ah, i've just looked into the operators in more details and -= is just for numbers... so this won't work. i presume this is going to be the wrong method then. Hi guys, This has been asked before, and i've seen many of the previous posts. And tried for hours. But finally i've broken and have to ask for help. What am I doing wrong here? Can someone please explain? Code: var u=document.forms["lead"]["name"].value; var v=document.forms["lead"]["city"].value; var x=document.forms["lead"]["country"].value; var y=document.forms["lead"]["mobile"].value; var z=document.forms["lead"]["email"].value; if (u==null || u=="") { alert("Please enter your first name."); return false; } if (v==null || v=="") { alert("Please enter your city."); return false; } if (isNaN(lead.y.value)) { alert("bloody work!"); return false; } if (x=="Argentina" && y.length < 11) { alert("Please enter a valid Argentinian phone number."); return false; } Thanks in advance. Working on an Adobe form (non web) The "Award" field is a bit troublesome. Award is not required every time therefore I left that out of it's field properties. I have also set the maxium amount of characters to 5. At times, it will be required therefore I want to set up validation that will return an error message if 1-3 characters are filled in but won't give any error message if 4 or 5 characters are entered in the field. I.e 0= Do nothing 1= Error 2= Error 3= Error 4= Do nothing 5= Do nothing Code: if ((event.value.length > 1) && (event.value.length < 4)) //trigger alert if 1-3 characters are entered { app.alert("The minimum amount of characters is 4"); event.rc = false; } else { // do nothing if 0,4 or 5 characters are entered } I have a problem thats above my head, im new to javascript. I want to be able to control the first three characters of an input string on a login form. If a user types GP15555 or JP15555 I want it to change to GPL5555 or JPL5555 respectively changing the "1" to an "L" on the prefix is this at all possible? any point in the right direction would be great. heres my code Code: </script> <script language="JavaScript" type="text/javascript"> //<![CDATA[ function Login(form) { var password = form.password.value; var pin = form.pin.value; var product = form.product.value; if (password) { var htsite = product + "/" + password + "/" + pin + "/index.html"; window.location = htsite; } else { alert("Please enter your password and pin."); } } // End --> //]]> </script> /thanks gp Hi, I am trying to only allow a person to enter alpha characters in this field and if they try to enter a number a pop up box will tell them they can only enter alpha characters. Can this be done? Here is my code: How would you like us to address you? ("Dear Pat" Dear <input name="SALUT" type="text" id="address2" style="color: #000000; border-left: 0px solid #008000; border-right: 0px solid #254D78; border-top: 0px solid #008000; border-bottom: 2px solid #0033CC; background-color: #EBE1BE" tabindex="5" size="15" maxlength="50" onFocus="if(this.value=='SALUT')this.value='';"> Any help would be greatly appreciated. Thanks I want to be able to use on function to check if a field has a value typed in on keyup. But I do not understand how I can get the javascript to pull the value in from the HTML. Here is my JavaScript: Code: <script type="text/javascript"> function validate_now(name) { if (document.upload.(name).value.length == 3) { alert("True"); return true; else { document.upload.(name).style.backgroundColor = "#990000"; return false; } } </script> HTML: Code: <input type="text" name="imageTitle" class="inputField" onkeydown="limitText(this.form.imageTitle,this.form.countdown1,30);" onkeyup="limitText(this.form.imageTitle,this.form.countdown1,30); validate_now('imageTitle')" /> <input readonly type="text" name="countdown1" size="3" value="30" style="background-color:#999999; border:0px; color:#339900; font-family:Calibri; font-weight:bold;"> I'm fairly new at this. I'm trying to build a store locator and trying to figure out how to pass an input value from one page to another page. User would input their zipcode or address in a form on one page and the map and locations would be called on another page using the input. I'm using ehound store locator platform (sample - here -> http://www.ehoundplatform.com/api/1....nd-google.html) The map/locator script is this Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"/> <title>Store Locator Demo using FreeHound and Google Maps V.3</title> <style type="text/css"> #map_canvas { height: 400px; width:710px; margin-bottom: 10px; } .addressBox { margin-bottom:10px; } </style> <script type="text/javascript" src="http://www.ehoundplatform.com/api/1.0/proximity.js?key=xz396aw1qe432q1"></script> <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false®ion=AU"></script> <script type="text/javascript"> var geocoder; var map; var bounds; var markersArray = []; var infoWindow; var mapCenterLat = '-28.1594'; var mapCenterLon = '135.6456'; function initialize() { geocoder = new google.maps.Geocoder(); var myOptions = { zoom: 4, center: new google.maps.LatLng(mapCenterLat, mapCenterLon), mapTypeId: google.maps.MapTypeId.ROADMAP } map = new google.maps.Map(document.getElementById("map_canvas"), myOptions); //initialise single info window to show only one at a time infoWindow = new google.maps.InfoWindow(); //improve usability by centering map around search point on zoom in/out google.maps.event.addListener(map, 'zoom_changed', function() { if(mapCenterLat && mapCenterLon) { setTimeout('centerMap(mapCenterLat, mapCenterLon)', 300); } }); } function addMarkerOverlay(location, title, infoBox, image) { var marker = new google.maps.Marker({ position: location, map: map, icon: image }); marker.setTitle(title); google.maps.event.addListener(marker, 'click', function() { infoWindow.setContent(infoBox); infoWindow.open(map, marker); }); markersArray.push(marker); } function deleteOverlays() { if (markersArray) { for (i in markersArray) { markersArray[i].setMap(null); } markersArray.length = 0; } } function searchAroundMe() { deleteOverlays(); bounds = new google.maps.LatLngBounds(); var address = document.getElementById("address").value; geocoder.geocode( { 'address': address}, function(results, status) { if (status == google.maps.GeocoderStatus.OK) { map.setCenter(results[0].geometry.location); //custom marker to mark initial search location var image = new google.maps.MarkerImage('search_location.png', // This marker is 32 pixels wide by 32 pixels tall. new google.maps.Size(32, 32), // The origin for this image is 0,0. new google.maps.Point(0,0), // The anchor for this image is the center of the red circle at 16,16. new google.maps.Point(16, 16) ); addMarkerOverlay(results[0].geometry.location, 'search spot', 'search initiated from here', image); bounds.extend(results[0].geometry.location); var searchLatitude = results[0].geometry.location.lat(); var searchLongitude = results[0].geometry.location.lng(); mapCenterLat = searchLatitude; mapCenterLon = searchLongitude; freeHound = new FreeHound( 'showLocs' ); search = new FH_Search(); search.count = 10; //number of locations to be returned in the result set search.max_distance = 0; //distance limit for proximity search in km, 0 for unlimited //search from a specific point using latitude and longitude of that point search.point = new FH_Location( new FH_LatLon( searchLatitude,searchLongitude ) ); //search.filters = new Array(); //search.filters.push( new FH_SearchFilter('cat_id', 'eq', '177') ); search.create_log = false; freeHound.proximitySearch( search ); } else { alert("Geocode was not successful for the following reason: " + status); } }); } function showLocs(response){ if ( response.error_code ) { alert(response.error_message); } if ( response.record_set ) { //show results in a table var resultsTable = '<table border="1" cellspacing="0" cellpadding="3" summary="">'; resultsTable += '<tr>'; resultsTable += '<td>#<\/td>'; resultsTable += '<td>Street Address<\/td>'; resultsTable += '<td>Town/Suburb/City<\/td>'; resultsTable += '<td>Postal Code<\/td>'; resultsTable += '<td>State/Province<\/td>'; resultsTable += '<td>Distance<\/td>'; resultsTable += '<td>Longitude<\/td>'; resultsTable += '<td>Latitude<\/td>'; resultsTable += '<\/tr>'; for (var record_count = 0, rl = response.record_set.length; record_count < rl; record_count++ ) { var record = response.record_set[record_count]; var title = record.details.location_name; var infoBoxContent = '<strong>Location #'+(record_count+1).toString()+'<\/strong>'; infoBoxContent += '<br \/>'+record.address.street_address+'<br \/>'+record.address.town + ', ' + record.address.postal_code +'<br \/>'; infoBoxContent += 'Distance: '+record.distance.km+'km<br \/>'; addMarkerOverlay(new google.maps.LatLng(record.latitude, record.longitude), title, infoBoxContent, null); if (record_count < 6) { bounds.extend(new google.maps.LatLng(record.latitude, record.longitude)); } resultsTable += '<tr>'; resultsTable += '<td>'+(record_count+1).toString()+'<\/td>'; resultsTable += '<td>'+record.address.street_address+'<\/td>'; resultsTable += '<td>'+record.address.town+'<\/td>'; resultsTable += '<td>'+record.address.postal_code+'<\/td>'; resultsTable += '<td>'+record.address.state+'<\/td>'; resultsTable += '<td>'+record.distance.km+'KM<\/td>'; resultsTable += '<td>'+record.longitude+'<\/td>'; resultsTable += '<td>'+record.latitude+'<\/td>'; resultsTable += '<\/tr>'; } map.fitBounds(bounds); resultsTable += '<\/table>'; var resultSet = document.getElementById('resultSet'); resultSet.innerHTML = resultsTable; } } function centerMap(lat,lon) { var centrePoint = new google.maps.LatLng(lat,lon); map.setCenter(centrePoint); } </script> </head> <body onload="initialize()"> <div class="addressBox"> <form action="" onsubmit="searchAroundMe(); return false;"> <input id="address" type="textbox" value=""> <input type="submit" name="search" value="Address Search"> </form> </div> <div id="map_canvas"></div> <div id="resultSet"></div> </body> </html> and the form itself would be on another page. Trying to pull the address input over. This obviously doesn't work Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Store Locator</title> </head> <body> <div> <form action="ehound.html" method="post"> <input id="address" name="address" type="textbox"> <input type="submit" name="search" value="Address Search"> </form> </div> </body> </html> I've looked around on passing inputs via php and such, but this script seems to call on javascript as well and I'm having trouble implementing anything that works. Any help would be greatly appreciated. Hello I am trying to call a javascript autocomplete function but I want to use a variable instead of an input field ID So this is my fuction: Code: $(function() { $("#tags").autocomplete({ source: "search.php?field=field1" }); }); <p><b>Field:</b><input type="text" input id = "tags" name="field1" size="60" ><br> Basically I want to use the same function for numerous input fields, so how can I pass a var instead of the input id ? Any help would be appreciated Hi all, I am new to JS and usually learn by studying code posted online and modify it to have it do what I need. Recently, I used a totaling plugin for an online ordering form which does the below: item1 qty(user input text) * preset price = total price item2 qty(user input text) * preset price = total price item3 qty(user input text) * preset price = total price -------------------------------------------------------- grand total -------------------------------------------------------- The JS code which passes the grandTotal variable is as below: Code: function ($this){ // sum the total of the $("[id^=total_item]") selector var sum = $this.sum(); $("#grandTotal").text( // round the results to 2 digits "₹" + sum.toFixed(2) ); } The problem I have is the above grandTotal displays the final value when put into a table like below: Code: <td align="right" id="grandTotal"></td> But I am unable to make it work by passing it into a variable within the form fields. I would like to do something like this: Code: <input type="text" name="grandTotal" id="grandTotal" readonly="readonly" /> Can somebody please help me fix this? Any help will be greatly appreciated. Thank you. Hi all, I'm having some trouble with the this... I have a PHP based calendar where the cells will change color depending on the number of clicks.. this all works fine, but is pointless if I can't send the outcome along in an email. I can do this with PHP but first need to get the values into a hidden field. This is what I have: Code: <script type="text/javascript"> function countClicks (obj){ if (!obj.count) { obj.count = 0; } obj.count++; if (obj.count > 4) {obj.count = 1}; if(obj.count == 1){ obj.style.color='#FFFFFF'; obj.style.backgroundColor='#66CC33'; obj.parentNode.style.backgroundColor='#66CC33'; document.getElementById("availability").value='Available'; } if (obj.count == 2){ obj.style.color='#FFFFFF'; obj.style.backgroundColor='#FF0000'; obj.parentNode.style.backgroundColor='#FF0000'; document.getElementById("availability").value='Not Available'; } if (obj.count == 3){ obj.style.color='#FFFFFF'; obj.style.backgroundColor='#FFCC33'; obj.parentNode.style.backgroundColor='#FFCC33'; document.getElementById("availability").value='Working'; } if (obj.count == 4){ obj.style.color='#000000'; obj.style.backgroundColor='#FFFFFF'; obj.parentNode.style.backgroundColor='#FFFFFF'; document.getElementById("availability").value='Not Set'; } } </script> and... Code: echo "<input type=\"hidden\" name=\"availability\" id=\"availability\" value=\"\">"; All I'm trying to do is populate value with either 'available', 'not available', 'working' or 'not set'... however, it is worth noting that each cell may have a different value, e.g. 1 cell might be working while the other is not available... so i need to pass the values of all the cells. Can anyone help me out here. Many thanks, Greens85 Hello, I use a iplocator api, which is javascript and gives out the city name, country and zipcode output PHP Code: <script language="JavaScript" src="http://www.somesite.com/somefile.js?key=apikey"></script> <script language="JavaScript"> <!-- document.write(ip2location_isp() + ', ' + ip2location_city() + ', ' + ip2location_zip_code() + ', ' + ip2location_net_speed()); //--> </script> my question or where i need help is that, i would like to output each of those as a hidden text field, so later i can store into mysq database with POST method from the hidden field. thank you in advance for your time n help Hello i am using a simple calendar date picker in which when u click a date is displayed in an input field. Using a javascript i am trying to retrieve data from a second page using this value but probably i am doing something wrong. 1st page: Code: <script type="text/javascript"> function showCustomer(str) { if (str=="") { document.getElementById("txtHint").innerHTML=""; return; } if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { document.getElementById("txtHint").innerHTML=xmlhttp.responseText; } } xmlhttp.open("GET","check6.asp?q="+str,true); xmlhttp.send(); } </script> </head> <body> <form> Check in: <input onchange="showCustomer(this.value)" size="22" id="f_date1" /><button id="f_btn1">...</button> <script type="text/javascript">//<![CDATA[ var cal = Calendar.setup({ onSelect: function(cal) { cal.hide() }, showTime: true }); cal.manageFields("f_btn1", "f_date1", "%Y-%m-%d"); //]]></script> </form> <br /> <div id="txtHint">here...</div> </body> </html> and in second one i am trying to get date like this: Code: sql_cmd.CommandText = "SELECT dbo.rooms.id, type, image, price,details FROM dbo.rooms, dbo.transactions WHERE dbo.rooms.id=dbo.transactions.roomid and '" & request.querystring("q") & "' not between checkin and checkout" Hey guys, I've been searching for a few hours and haven't been able to find a code snippet to see if this is available. I'm attempting to pass text from my website to another website that has a form setup on it. I'd like to fill in the pertinent data for my users on the page that I load for them. I cannot make any changes to the receiving page as it is run by another company. I've pasted some of the code that is available on the receiving form. Thanks for any help. Code: <script type="text/javascript"> //<![CDATA[ var theForm = document.forms['form1']; if (!theForm) { theForm = document.form1; } function __doPostBack(eventTarget, eventArgument) { if (!theForm.onsubmit || (theForm.onsubmit() != false)) { theForm.__EVENTTARGET.value = eventTarget; theForm.__EVENTARGUMENT.value = eventArgument; theForm.submit(); } } //]]> </script> <input name="txtBranch" type="text" maxlength="4" id="txtBranch" tabindex="1" style="height:14px;width:35px;" /> <input name="txtClient" type="text" maxlength="11" size="11" id="txtClient" tabindex="2" style="height:14px;" /> Im trying to fill in the data in these 2 input fields. I'm new in web-development. I've searched it but it's not found. I make a input then how i get value of it for javascript value?
Code: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <script type="javascript/text"> <!-- function clearInputField( input, def ) input = document.getElementById( input ); if ( input.value == def ) { input.value = ''; } } --> </script> </head> <body> <b>Testing Input</b> <input id="input" onclick="JavaScript: clearInputField('input', 'Enter Text');" type="text" size="31" value="Enter Text" /> <body> </html> This gives me a "Uncaught ReferenceError: clearInputField is not defined" error and I'm not sure why...? Hi all, I have a complicated (well to me it is!) problem with a form I am creating for my site. The form has three sections with the ability to add another field unlimited times. There is one for adding ingredients, one for equipment and one for steps The name and id does increment on all 3 however the problem is they seem to all be using the same count, by this I mean that if I add 2 steps (which brings the count to 3) and then add an ingredient, the ingredient id goes to ingredient4 - obviously because it is taking the count that step has set. I am no javascript guru, I am more a designer so I'm really struggling, Ive been working on this one for days.. There is also another problem in that if I create say 3 steps bringing the count up to step4 and then remove the second step, I cant see how I can bring the other steps after step2 count down by one, at the moment step4 and step3 are staying as step3 and step4 but because step2 was removed they should drop down to becoming step2 and step3. My php that inserts the data into my db isnt working because the ids keep getting messed up I have a demo URL up on ajburchell.com/form.html If anyone can help me with this I will be extremely grateful Thank you in advance I have a script where I move randomly users from one multiple selectfield to another and that part works perfectly, but... When I want to submit the form I don't get any users passed along, course they are not "selected". I have then read around on the net and I need to create an elemet with a hidden input field where all the randomly selected users is inserted to with comma separation, but dont know how?!?! This is what I got: Code: function randomusers(){ var given = 3, used = {}, randnum, opts = $('#select1 option'), olen = opts.length; function ran() { // generate a unique random number randnum = Math.floor(Math.random() * olen); return used['u'+randnum] ? ran() : randnum; } for (var i = 0; i < given; i++) { // get the correct quantity of randoms used['u'+ran()] = true; } opts.filter(function(index) { // remove all options that are not one of the randoms return !!used['u'+index]; }).appendTo('#select2'); } I have tryied to insert this: appendTo('#select2' + '<input type="hidden" name="test[]" value="" />'); but that didn't seem right... Please help :-) i was wondering what event would clear an input field that has a value in it... so a user can type their own value.... any examples? Below is my previous code I had working in the manner it would change the price, sub_total, tax, sh, total, and total_paid input fields to 0. There are two problems with this... 1. When it outputs to the input fields, the value displays as 0 instead of 0.00. 2. I need to have it only react when the value typed into the input field "trees_sold" is "0". If any higher, I would like it to ignore the statement. Code: <!-- Comp all prices to zero value --> <SCRIPT LANGUAGE="JavaScript"> var trees_sold = 0.00; function InitSaveVariables(form) { price = form.price.value; sub_total = form.sub_total.value; tax = form.tax.value; sh = form.sh.value; total = form.total.value; total_paid = form.total_paid.value; } function CompPrices(form) { if (trees_sold == 0.00) { InitSaveVariables(form); form.price.value = 0.00; form.sub_total.value = 0.00; form.tax.value = 0.00; form.sh.value = 0.00; form.total.value = 0.00; form.total_paid.value = 0.00; } } </script> Code: <input name="trees_sold" id="trees_sold" size="15" onkeyup="javascript:CompPrices(this.form);" maxlength="15" /> Below is my current code I'm working with that I can't seem to get to function properly. I've modified the first two lines of code here, and am attempting to pull any data that is typed in and automatically take into consideration if it is a "0" value, it reacts as my code below says "if (trees_sold == 0.00)" and if anything else, it will not do anything. This is not working unfortunately. Code: <!-- Comp all prices to zero value --> <SCRIPT LANGUAGE="JavaScript"> form.trees_sold.value = ""; trees_sold = form.trees_sold.value; function InitSaveVariables(form) { price = form.price.value; sub_total = form.sub_total.value; tax = form.tax.value; sh = form.sh.value; total = form.total.value; total_paid = form.total_paid.value; } function CompPrices(form) { if (trees_sold == 0.00) { InitSaveVariables(form); form.price.value = 0.00; form.sub_total.value = 0.00; form.tax.value = 0.00; form.sh.value = 0.00; form.total.value = 0.00; form.total_paid.value = 0.00; } } </script> Code: <input name="trees_sold" id="trees_sold" size="15" onkeyup="javascript:CompPrices(this.form);" maxlength="15" /> Anyone have any ideas? Thank you. |