JavaScript - Need Help Using Url Variables To Write A Form Field
Using the url test.html?a=john&b=doe
I am using the following code: <script type="text/javascript" language="javascript"> function getUrlVars() { var map = {}; var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi; function(m,key,value) { map[key] = value; }); return map; } var john=getUrlVars(map[a]); alert (getUrlVars(map[a])) alert (john) </script> I can't seem to get an alert to show me anything. The eventual result is not an alert, but a document.write to post the url contents to various form fields for firstname= and lastname= etc. I am really having a hard time using the document.write function, and am not sure how to employ it, whether in the same script statement or in a separate script in the body. Similar TutorialsI need help troubleshooting javascript I am using to concatenate two fields in a form and populating a hidden field with them. Here's the javascript: <script type="text/javascript"> function combName() { var fname = document.forms[0].fname.value; var lname = document.forms[0].lname.value; document.forms[0].name.value = fname + " " lname; } </script> Here are the form fields: <input id="fname" name="fname" type="text"> <input id="lname" name="lname" type="text" onKeyUp="combName()"> <input name="name" type="hidden" id="name" size="20" maxlength="80"> <input name="Submit" type="submit" id="OnSubmit" value="OnSubmit"> What am I doing wrong? Thanks. Hello, I have several event handlers on my page; one of them doesn't work. I'll post them all here, indicating how they are executed: #1: Works [CODE]<script type="text/javascript"> function combName() { var fname = document.forms[0].fname.value; var lname = document.forms[0].lname.value; document.forms[0].name.value = fname + " " + lname; } </script>[CODE] NOTE: The "lname" field uses "onKeyUp" to make the script run. A hidden field named "name" is populated with the concatenation. #2: Works (this script is too long to post; it is a validation script and runs via the "onSubmit" in the form tag.) #3: Doesn't Work [CODE]<script type="text/javascript"> function combPrograms() { document.forms[0].00N70000002WNax.value = "1st Choice: " + document.forms[0].sf1.value + document.forms[0].alameda1.value + document.forms[0].sanmateo1.value + document.forms[0].marin.value + document.forms[0].cc1.value + "2nd Choice: " + document.forms[0].sf2.value + document.forms[0].alameda2.value + document.forms[0].sanmateo2.value + document.forms[0].marin2.value + document.forms[0].cc2.value; } </script>[CODE] Note: 1. Not all of the values for Choice 1 and Choice 2 are populated. 2. For that reason, one of the later, unrelated text fields in the form has "onKeyUp="combPrograms()" to run the event. 3. A hidden field named 00N70000002WNax is populated with the concatenation. Any help is much appreciated! 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 I'm having a heck of a time getting a code to populate several hidden fields in the following form that I'm extracting from the url. It is posting to the appropriate CGI, however the hidden variables are not submitted. Code: <script type="text/javascript"> str=document.URL; temp = str.split('//'); temp1 = temp[1]; temp2 = temp1.split('.'); temp3 = str.split('/'); domain = ('http://' + temp3[2]); returnthanks = (domain); association = temp2[0]; poibegin = (str.lastIndexOf('/')+1); poiend = (str.lastIndexOf('.')); poi = (str.substring(poibegin)); </script><script language="JavaScript" type="text/javascript"> function doSubmit(){ document.w2lForm('00N30000004C6Rg').value=association; document.w2lForm.('00N30000004C2u2').value=poi; document.w2lForm.('retURL').value=returnthanks; document.w2lForm.submit(); } </script> <h6 style="text-align: center">Submit your information and a professional will contact you.</h6> <form method="post" action="https://www.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8" name="w2lForm"> <input type="hidden" name="oid" value="005040020320220B3eR" /> <label for="first_name">First Name</label> <input id="first_name" maxlength="40" name="first_name" type="text" /><br /> <label for="last_name">Last Name</label><input id="last_name" maxlength="80" name="last_name" type="text" /><br /> <label for="email">Email</label><input id="email" maxlength="80" name="email" type="text" /><br /> Best Time to Call:<select id="00N30000004NaDm" title="Best Time to Call" multiple="multiple" name="00N30000004NaDm"> <option value="(select at least one)">(select at least one)</option> <option value="Before 9AM (EST)">Before 9AM (EST)</option> <option value="9AM to 1PM">9AM to 1PM</option> <option value="1PM to 6PM">1PM to 6PM</option> <option value="After 6pm">After 6pm</option> </select><br /> <input id="00N30000004C2u2" type="hidden" name="00N30000004C2u2" /> <input id="00N30000004C6Rg" type="hidden" name="00N30000004C6Rg" /> <input type="submit" name="submit" value="Submit Request Information" /> </form> I've set up a mock registration form page so I can learn a bit about javascript's form validation. (newbie) I want to try to attempt to style the border of a form field green when the user enters the correct info into the form text field and red on all other fields if the user doesnt enter any info into them. When i test it, enter the right info into the username field, leave the others blank, and hit the submit button it styles the username field green ok but it doesnt make the next fields (password and so on) red. Could someone please explain what I am doing wrong? here is my code so far... Note: just for testing purposes I've put return false on everything so it displays a message when everythings ok. Code: .... <script type="text/javascript"> window.onload = function() { document.forms[0].username.focus(); } function validate(form) { var form = document.getElementById("reg"); var e = document.getElementById("error"); e.style.background = "red"; for(var i = 0; i < form.elements.length; i++) { var el = form.elements[i]; if(el.type == "text" || el.type == "password") { if(el.value == "") { e.innerHTML = "Please fill in all fields!"; el.style.border = "1px solid red"; el.focus(); return false; } else { el.style.border = "1px solid green"; return false; } } } var un = form.username; un.value = un.value.replace(/^\s+|\s+$/g,""); if((un.value.length < 3)|| (/[^a-z0-9\_]/gi.test(un.value))) { e.innerHTML = "Only letters,numbers and the underscore are allowed (no spaces) - 3-16 characters"; un.focus(); return false; } var pw = form.password; pw.value = pw.value.replace(/^\s+|\s+$/g,""); if((pw.value.length < 3) || (/[^a-z0-9]/gi.test(pw.value))) { e.innerHTML = "Only letters and numbers are allowed (no spaces) - 3-16 characters"; pw.focus(); return false; } e.innerHTML = "You filled in all the fields, well done!"; e.style.background = "green"; return false; } </script> </head> <body> <div id="wrapper"> <div id="header"> <h1>My Cool Website</h1> </div> <div id="content"> <div class="padding"> <h2>Registration</h2> <p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Duis ligula lorem, consequat eget, tristique nec, auctor quis, purus. Vivamus ut sem. Fusce aliquam nunc vitae purus. Aenean viverra malesuada libero. Fusce ac quam. Donec neque. Nunc venenatis enim nec quam. Cras faucibus, justo vel accumsan aliquam, tellus dui fringilla quam, in condimentum augue lorem non tellus. Pellentesque id arcu non sem placerat iaculis. Curabitur posuere, pede vitae lacinia accumsan, enim nibh elementum orci, ut volutpat eros sapien nec sapien. Suspendisse neque arcu, ultrices commodo, pellentesque sit amet, ultricies ut, ipsum. Mauris et eros eget erat dapibus mollis. Mauris laoreet posuere odio. Nam ipsum ligula, ullamcorper eu, fringilla at, lacinia ut, augue. Nullam nunc.</p> <form id="reg" action="#" method="post" onsubmit="return validate(this)"> <div id="error"></div> <div><label for="username">Username</label></div> <div><input type="text" name="username" id="username" size="30" maxlength="16" /></div> <div><label for="password">Password</label></div> <div><input type="password" name="password" id="password" size="30" maxlength="16" /></div> <div><label for="c_password">Confirm Password</label></div> <div><input type="password" name="c_password" id="c_password" size="30" maxlength="16" /></div> <div><label for="email">Email address</label></div> <div><input type="text" name="email" id="email" size="30" maxlength="200" /></div> <div><label for="c_email">Confirm Email address</label></div> <div><input type="text" name="c_email" id="c_email" size="30" maxlength="200" /></div> <div><label for="firstname">First name</label></div> <div><input type="text" name="firstname" id="firstname" size="30" maxlength="100" /></div> <div><label for="surname">Surname</label></div> <div><input type="text" name="surname" id="surname" size="30" maxlength="100" /></div> <div><label for="gender">Gender</label></div> <div> <div><input type="radio" name="gender" id="gender" value="m" checked="checked" />Male</div> <div><input type="radio" name="gender" value="f" />Female</div> </div> <div><input type="submit" value="Register" name="submit" /></div> </form> </div> </div> <div id="footer"> <p>Copyright © 2009 My Cool Website</p> </div> </div> </body> </html> Hello. My goal is for the user's input on their first visit to redirect their landing page in the future. I am a novice and any help is very much appreciated. The form's drop down menu includes three cities (Calgary, Toronto, Vancouver). When the user presses "submit form", the script should create a cookie to store the user's city selection. Next time the user visits the site, they should be redirected to their city's site, ie. "/vancouver.html" Right now, the code is returning an error from the onload("redirect();") function. The error indicates I am trying to redirect to "/[object HTMLSelectElement].html", but I am not sure if the trouble is in reading or writing the cookie. For simplicity, I've removed most of the other content from this page (my cookie.js is attached as a .doc): Code: <title>Site Title</title> <script type="text/javascript" src="cookie.js"></script> <script language="JavaScript" type="text/javascript"> function redirect() { userCity = readCookie ("user_city"); if (userCity) { window.location.replace(userCity + ".html"); } else { window.location.replace("index.html"); } } function setCity(box) { { var userCity =(document.welcomeSignUp.userCity); for (i=0; i<userCity.length; i++) { if (userCity[i].name != box.name) { userCity[i].selectedIndex = 0; } } } writeCookie("user_city", userCity, 5 * 365); } </script> <link type="text/css" rel="stylesheet" href="style.css" /> </head> <body> <form id="welcomeSignUp" action="" method="get" name="welcomeSignUp" onload="redirect();"> Your Email address: <input type="text" name="email" value="" size ="20" /> <br /> Choose Your City: <select name="userCity" size="20"> <option value="one">Calgary</option> <option value="two">Toronto</option> <option value="three">Vancouver</option> </select> <a href="index.html"><button class="rounded" onclick="setCity(this);"> <span>submit form</span> </button></a> </form> </body> </html> Hi ! i sometimes are able to alter simple javascript, but i need help with the following. MaxMind.com has a javascript or geotargetting. It displays the country where ur at. I need this output in a form, so i can store it in a database. this is the script i use: <script language="JavaScript" src="http://j.maxmind.com/app/country.js"></script> <br>Country Code: <script language="JavaScript">document.write(geoip_country _code());</script> <br>Country Name: <script language="JavaScript">document.write(geoip_country _name());</script> How can i get the country name to be displayed in an input field ? something like: <form name="xx" action="somepage.htm" method="post"> <input type="Text" size="50" name="country" value="country name"> </form> Hey there, I'm new to the magical world of jscript- have been introduced to it as I'm creating a fictional retail company for a business assignment. The code below is for my 'products' page where I've put a ''checkout' form at the bottom of. There are a few products inside a form...it currently uses jscript to work out a total value of all the product quantities chosen by the user. What I'm trying to do though is get the code to show which products the user has chosen (and possibly how many of each) in the 'Checkout' form at the bottom of the page. Everytime I try anything, the code calculate falls apart Would really appreciate any help or advice you could provide - cheers studentnet.kingston.ac.uk/~k0602276/Products.html Code: <head> <!-- Cart Script --> <script language="JavaScript" type="text/javascript"> function CalculateTotal(frm) { var order_total = 0 for (var i=0; i < frm.elements.length; ++i) { form_field = frm.elements[i] form_name = form_field.name if (form_name.substring(0,4) == "PROD") { item_price = parseFloat(form_name.substring(form_name.lastIndexOf("_") + 1)) item_quantity = parseInt(form_field.value) if (item_quantity >= 0) { order_total += item_quantity * item_price } } } frm.TOTAL.value = round_decimals(order_total, 2) } function round_decimals(original_number, decimals) { var result1 = original_number * Math.pow(10, decimals) var result2 = Math.round(result1) var result3 = result2 / Math.pow(10, decimals) return pad_with_zeros(result3, decimals) } function pad_with_zeros(rounded_value, decimal_places) { // Convert the number to a string var value_string = rounded_value.toString() // Locate the decimal point var decimal_location = value_string.indexOf(".") // Is there a decimal point? if (decimal_location == -1) { decimal_part_length = 0 value_string += decimal_places > 0 ? "." : "" } else { decimal_part_length = value_string.length - decimal_location - 1 } var pad_total = decimal_places - decimal_part_length if (pad_total > 0) { for (var counter = 1; counter <= pad_total; counter++) value_string += "0" } return value_string } </script> </head> <body> <!-- Products --> <div class="Products"> <table title="Products" id="Products" border="1" table width="100%" border=0 cellpadding=0 cellspacing=0 bgcolor="#777777"> <form method="post" action="order.php"> <TD COLSPAN=3 ALIGN="CENTER"><h3>Premium Acoustic Guitars</h3></TD> <TR><TD ALIGN="CENTER"><b>Quantity:</b></TD> <TD ALIGN="CENTER"><b>Description</b></TD><TD ALIGN="CENTER"><b>Price</b> <i>(each)</i></B></TD></TR> <TR><TD ALIGN="CENTER"><INPUT TYPE=TEXT NAME="PROD_G1_259.99" SIZE=3 MAXLENGTH=3 onChange="CalculateTotal(this.form)"></TD> <TD><img width=100 height=200 hspace=1 vspace=1 align= "left" src= "products/G1- Fnd Tim Armstrong Hellcat.jpg"><b>Model Name:</b> Tim Armstrong Hellcat Acoustic <br><b>Colours:</b> Natural <br><b>Body:</b> Solid Mahogany <br><b>Neck:</b> Maple <br><b>Fingerboard:</b> Rosewood <br><b>No. of Frets:</b> 20 <br><b>Unique Features:</b> 4-Ply Tortoise Shell Pickguard, Hellcat Position Inlays, Double Skull Inlays at 12th Fret, Tim Armstrong, Signature on Truss Rod Cover, <br><b>Strings:</b> D'Addario EXP-26 Phosphor Bronze, Gauges .011 to .052 <br><b>Accessories:</b> Tim Armstrong "Let's Go" Guitar Strap</TD> <TD ALIGN="RIGHT">£259.99</TD></TR> <TR><TD ALIGN="CENTER"><INPUT TYPE=TEXT NAME="PROD_G2_129.99" SIZE=3 MAXLENGTH=3 onChange="CalculateTotal(this.form)"></TD> <TD><img width=100 height=200 hspace=1 vspace=1 align= "left" src= "products/G2- Fnd GDO-200.jpg"><b>Model Name:</b> GDO-200<br> <b>Colours:</b> Green, Blue, Maroon<br> <b>Body:</b> Maple<br> <b>Neck:</b> Mahogany<br> <b>Fingerboard:</b> Rosewood<br> <b>No. of Frets:</b> 20<br> <b>Unique Features:</b> Fender "F" Inlay at 12th Fret, Side Dot Position Inlays, Ivory Body and Neck Binding Strings: D'Addario EXP-26 Phosphor Bronze, Gauges .011 to .052<br> <b>Accessories:</b> None</TD><TD ALIGN="RIGHT">£129.99</TD></TR> <TR><TD ALIGN="CENTER"><INPUT TYPE=TEXT NAME="PROD_G3_2099" SIZE=3 MAXLENGTH=3 onChange="CalculateTotal(this.form)"></TD> <TD><img width=100 height=200 hspace=1 vspace=1 align= "left" src= "products/G3- Gib Hummingbird.jpg"><b>Model Name:</b> Hummingbird<br> <b>Colours:</b> Heritage Cherry Sunburst<br> <b>Body: </b>Solid Mahogany<br> <b>Neck:</b> Maple<br> <b>Fingerboard: </b>Rosewood<br> <b>No. of Frets:</b> 20<br> <b>Unique Features:</b> 4-Ply Tortoise Shell Pickguard with floral and hummingbird inlay, Nickel Grover rotomatic tuners<br> <b>Strings:</b> Gibson J200 Phosphor Bronze Acoustic Guitar Strings Gauges .011 to .052<br> <b>Accessories:</b> L.R. Baggs Element Active Acoustic Pickup System</TD><TD ALIGN="RIGHT">£2,099</TD></TR> <TR><TD ALIGN="CENTER"><INPUT TYPE=TEXT NAME="PROD_G4_399" SIZE=3 MAXLENGTH=3 onChange="CalculateTotal(this.form)"></TD> <TD><img width=100 height=200 hspace=1 vspace=1 align= "left" src= "products/G4- Gib 1942 J-45 Legend.jpg"><b>Model Name:</b> 1942 J-45 Legend<br> <b>Colours:</b> Vintage Sunburst<br> <b>Body: </b>Solid Mahogany<br> <b>Neck:</b> Maple<br> <b>Fingerboard: </b>Rosewood<br> <b>No. of Frets: </b>20<br> <b>Unique Features:</b> Hand-coloured tortoise "tear drop" pick guard<br> <b>Strings:</b> Gibson J200 Phosphor Bronze Acoustic Guitar Strings Gauges .011 to .052<br> <b>Accessories:</b> None</TD><TD ALIGN="RIGHT">£399</TD></TR> <TR><TD ALIGN="CENTER"><INPUT TYPE=TEXT NAME="PROD_G5_599.99" SIZE=3 MAXLENGTH=3 onChange="CalculateTotal(this.form)"></TD> <TD><img width=100 height=200 hspace=1 vspace=1 align= "left" src= "products/G5- Ep AJ-500R.jpg"><b>Model Name:</b> AJ-500R<br> <b>Colours:</b> Natural Satin<br> <b>Body:</b> Solid Mahogany<br> <b>Neck:</b> Maple<br> <b>Fingerboard:</b> Rosewood<br> <b>No. of Frets:</b> 20<br> <b>Unique Features:</b> Mother-of-Pearl "stickpin" inlay, Offset Notch peghead<br> <b>Strings: </b> Gibson J200 Phosphor Bronze Acoustic Guitar Strings Gauges .011 to .052<br> <b>Accessories:</b> None</TD> <TD ALIGN="RIGHT">£599.99</TD></TR> <TR><TD ALIGN="CENTER"><INPUT TYPE=TEXT NAME="PROD_G6_199.99" SIZE=3 MAXLENGTH=3 onChange="CalculateTotal(this.form)"></TD> <TD><img width=100 height=200 hspace=1 vspace=1 align= "left" src= "products/G6- Ep EL00.jpg"><b>Model Name:</b> EL-00<br> <b>Colours:</b> Black Vintage Sunburst<br> <b>Body:</b> Solid Mahogany<br> <b>Neck:</b> Maple<br> <b>Fingerboard:</b>Rosewood<br> <b>No. of Frets:</b> 20<br> <b>Unique Features:</b> 10 Year Guarantee<br> <b>Strings:</b> Gibson J200 Phosphor Bronze Acoustic Guitar Strings Gauges .011 to .052<br> <b>Accessories:</b>None</TD><TD ALIGN="RIGHT">£199.99</TD></TR> <TR><TD ALIGN="CENTER"><INPUT TYPE=TEXT NAME="PROD_G7_1200" SIZE=3 MAXLENGTH=3 onChange="CalculateTotal(this.form)"></TD><TD><img width=100 height=200 hspace=1 vspace=1 align= "left" src= "products/G7- Tay Jason Mraz Signature.jpg"><b>Model Name:</b> Jason Mraz Signature</br> <b>Colours:</b> Natural<br> <b>Body:</b> Red Cedar and Indian Rosewood<br> <b>Neck: </b>Tropical American Mahogany<br> <b>Fingerboard: </b>Rosewood<br> <b>No. of Frets: </b>20<br> <b>Unique Features: </b>Zodiac Koa Cypress rossette, ebony fretboard,<br> <b>Strings:</b>D'Addario Pro-Arte Extra Hard Tension, Gauges .011 to .052<br> <b>Accessories:</b>Taylor Deluxe Hardshell Case</TD> <TD ALIGN="RIGHT">£1,200</TD></TR> <TR><TD ALIGN="CENTER"><INPUT TYPE=TEXT NAME="PROD_G8_1399" SIZE=3 MAXLENGTH=3 onChange="CalculateTotal(this.form)"></TD> <TD><img width=100 height=200 hspace=1 vspace=1 align= "left" src= "products/G8- Tay 315ce.jpg"><b>Model Name:</b> Taylor 315ce<BR> <b>Colours:</b> Natural<BR> <b>Body:</b> Sitka Spruce<br> <b>Neck:</b> Tropical American Mahogany<br> <b>Fingerboard:</b> Rosewood<br> <b>No. of Frets:</b> 20<br> <b>Unique Features:</b> Adjustable Truss Rod<br> <b>Strings:</b> Elixir Medium Gauge Strings with Nanoweb Coating, Gauges .011 to .052 <br> <b>Accessories:</b> Taylor Hardshell Case</TD> <TD ALIGN="RIGHT">£1,399</TD></TR> <TR><td><INPUT TYPE=RESET VALUE="Empty Basket"></td> <TD><b>TOTAL</b></TD> <TD ALIGN="RIGHT"><INPUT TYPE=TEXT NAME="TOTAL" SIZE=10 onFocus="this.form.elements[0].focus()"></TD> </table> <table title="Buy Now" id="Buy Now" border="1" table width="100%" border=0 cellpadding=0 cellspacing=0 bgcolor="#777777"> <tr> <a name="Checkout"></a> <TD COLSPAN=3 ALIGN="CENTER"><h3>Checkout</h3></TD></TR> <tr><td colspan=2><strong>Please fill your details in the form below:</strong></td></tr> <tr><td>Department:</td><td><select name="sendto"> <option value="k0602276@kingston.ac.uk">AcuSound Sales</option></td></tr> <tr><td><font color=red>*</font> Name:</td><td><input size=25 name="Name"></td></tr> <tr><td><font color=red>*</font> Email:</td><td><input size=25 name="Email"></td></tr> <tr><td>Phone:</td><td><input size=25 name="Phone"></td></tr> <tr><td>Subscribe to<br> mailing list:</td><td><input type="radio" name="list" value="No"> No Thanks<br> <input type="radio" name="list" value="Yes" checked> Yes, keep me informed<br></td></tr> <tr><td> Address:</td> <td><textarea name="Address" rows=5 cols=35></textarea></td></tr> <tr><td>Total:</td><td><input size=25 name="###"></td></tr> <tr><td colspan=2 align=center><input type=submit name="send" value="Buy Now"></td></tr> <tr><td colspan=2 align=center><small>A <font color=red>*</font> indicates a field is required</small></td></tr> </table> </Form> </body> How can I add a form field value to a url. I tried the below but it no work. Code: href="index2.php?q=4&id=+document.theForm.lists.value+&picklist" I have a form which has various fields which are arrays (so the name of a field may be myField[]). The reason for this is that the form has add buttons to add another field or fields for the purpose of entering another email address, etc., to send invitations and do other things. The problem that I am running into is how to access the individual fields in an array of fields inside javascript to do form validation. So if I have an email address field name emailAddress[], and using the add button, the user of my site adds 3 other copies of the emailAddress[] field, I want to then do form validation onSubmit to ensure those email address are valid using standard procedures. However, inside the javascript code, how do I access the individual fields that make up emailAddress[]? I just cannot find anywhere online the proper way to get at these values. If anyone can help me, I would greatly appreciate it. Happy Holidays Hi! I use the :: Form field Progress Bar from DynamicDrive: Form field Progress Bar Now I trided to change the text when the textarea is full "Limit:100%" to "Your max. characters is reached" I trided it but with no luck. This is the main code.. Code: <script type="text/JavaScript"> function textCounter1(field,counter,maxlimit,linecounter) { // text width// var fieldWidth = 137; var charcnt = field.value.length; // trim the extra text if (charcnt > maxlimit) { field.value = field.value.substring(0, maxlimit); } else { // progress bar percentage var percentage = parseInt(100 - (( maxlimit - charcnt) * 100)/maxlimit) ; document.getElementById(counter).style.width = parseInt((fieldWidth*percentage)/100)+"px"; document.getElementById(counter).innerHTML="Limiet: "+percentage+"%" // color correction on style from CCFFF -> CC0000 setcolor(document.getElementById(counter),percentage,"background-color"); } } function setcolor(obj,percentage,prop){ obj.style[prop] = "rgb(80%,"+(100-percentage)+"%,"+(100-percentage)+"%)"; } </script> This is the place where the text is set. Code: ((fieldWidth*percentage)/100)+"px"; document.getElementById(counter).innerHTML="Limiet: "+percentage+"%" Help would be highly appreciated ! greetings Jardin I need to learn how to clear form fields when a user clicks on them. Here is the site in question: http://www.yourvancouvermortgagebroker.ca/apply They used to work, but then I changed the field value and now it doesn't work on some of the fields (whichever ones I changed). Here is a link to the .js file: http://www.yourvancouvermortgagebroker.ca/js/apply.js Hi there, I have a html form, and I need it so that when a user clicks a button, it adds a field into the form. I also need it to write <td></td> around the new field, and I need it to write this in a specific part row of a table. How would I go about doing this? I've tried searching for the past two hours, but no luck. Many thanks, I appreciate it, Jason function checkValidFormInput() { if (document.getElementsByName('customerName').value != '') { document.getElementById('customerNameImg').innerHTML = '<img alt="Valid" src="images/greenTick.png">'; } else { document.getElementById('customerNameImg').innerHTML = '<img alt="Invalid" src="images/redX.png">'; } if (document.getElementsByName('customerEmail').length > 0) { document.getElementById('customerEmailImg').innerHTML = '<img alt="Valid" src="images/greenTick.png">'; } else { document.getElementById('customerEmailImg').innerHTML = '<img alt="Invalid" src="images/redX.png">'; } } Is there a way to give an input or textarea field the focus and set the focus to begin right at the end of the current text in the field?
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. hi all, i was hoping somebody could help me out. i'm trying to write a code that generates a random number between 1 and 9999 on page load, concatenates it with "pwn" at the start, and adds it to a disabled form text input box. this is the code i have below, but it's not working at all. any help would be greatly appreciated. in the head section Code: <script type="text/javascript"> function createcode() { var randomnumber = Math.floor(Math.random()*10000); var homecode = 'pwn' + randomnumber; } </script> my body tag Code: <body onload="createcode()"> and the form field itself Code: <input type="text" name="homename" id="homename" disabled="disabled" /> <script type="text/javascript"> document.getElementByID("homename").value = homecode; document.write(homecode); </script> thanks in advance. Greetings, I'm working on a php/mysql app that has multiple tabs with multiple form fields. I am trying to incorporate a javascript form field detection function that alerts the user that they have not submitted their changes if they try to navigate away. The detection works as designed, but the problem I am having is when the form is submitted, the script senses an unload and still fires the alert. The form submits to itself and updates the database and then reloads the page with the new values. Is there a way to have the script ignore the forms submit url and skip the form check? Here is the code ( NOT mine, found it somewhere else.) Code: <script language="javascript"> var ids = new Array('description'); var values = new Array('<?php echo $detail['description']; ?>'); function populateArrays() { // assign the default values to the items in the values array for (var i = 0; i < ids.length; i++) { var elem = document.getElementById(ids[i]); if (elem) if (elem.type == 'checkbox' || elem.type == 'radio') values[i] = elem.checked; else values[i] = elem.value; } } var needToConfirm = true; window.onbeforeunload = confirmExit; function confirmExit() { if (needToConfirm) { // check to see if any changes to the data entry fields have been made for (var i = 0; i < values.length; i++) { var elem = document.getElementById(ids[i]); if (elem) if ((elem.type == 'checkbox' || elem.type == 'radio') && values[i] != elem.checked) return "Your changes have not been saved. Are you sure you want to leave?"; else if (!(elem.type == 'checkbox' || elem.type == 'radio') && elem.value != values[i]) return "Your changes have not been saved. Are you sure you want to leave?"; } // no changes - return nothing } } </script> The url of the page is "edit.php?&mode=edit&t=2&id=284&cn=2009-002" The only detectable change to the query string would be the 't' variable. Basically what I want to do is have the script look for a change in the 't' variable and if detected, check the form values for changes. If 't' doesn't change, skip the script completely. Thanks.. Hi. I have a form and if a field is blank a message pops up. This doesnt stop my php from running though and takes the user to another page. Is there a line to keep them on that page untill all fields are filled out? code so far is simple. <script type="text/javascript" language="JavaScript"> function nameempty() { if ( document.form.subject1.value == '' ) { alert('No name was entered!') return false; } } </script> //then down the bottom I have a small bit that implements that code |