JavaScript - Add Form Field Value To Url??
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" Similar TutorialsI'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> 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 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">'; } } 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 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 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?
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 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! 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 I have some code that uses a form, and will check it and show an image. If you have/know a script that is simple, let me know! Otherwise, I'm wondering if someone who is proficient in JS/HTML could help me with this task. It's all coded, I just need some help with an error I am getting. Thanks, Blockis Though I know nothing about Javascript, that didn't stop them from assigning me the task of mothballing our Excel spreadsheets and going to fillable .PDF forms. Here's my first of many questions: In one of my fillable PDF forms, I take the numbers (entered by the user) from two or three fields and calculate those placing the answer in a seperate field. Since we work with very large, and very small numbers, I want the number in the answer field to be displayed in scientific notation. Adobe Acrobat is not very flexible when it comes to selecting a number format, so a script is obviously needed to do the conversion. I've also noticed that Adobe doesn't like the user entering a number in a field in scientific notation. My number calculates out correctly if you enter .000000274 in the field, but does nothing if you enter 2.74E-7. Help with that would also be greatly appreciated. Don I have been staring at this code for too long and need some help. I want to pass a value received through the Url to another screen with new data by a form using the method="get". I have tried several different ways, my latest attempt was to use a hidden field hoping that would add to the url string but it isn't working. Thank you in advance Here is my code, its not pretty 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>Field Location</title> <link rel="stylesheet" href="css/INTERPRETING_TR_CONTROL_ELECTRICAL_READINGS.css" type="text/css" media="screen" /> </head> <body> <div> <form id="form1" name="form1" method="get" action="./nameplateInformation.html"> <h3>Where is this field located?</h3> <select name="fieldValue" id="fieldValue" title="Where is this field located"> <option value="field1">Inlet Field</option> <option value="field2">Second Field</option> <option value="field3">Third Field</option> <option value="field4 ">Outlet Field</option> </select> <script type="text/javascript"> (function(){ // Import GET Vars :D document.getVars = []; var urlHalves = String(document.location).split('?'); if(urlHalves[1]){ var urlVars = urlHalves[1].split('&'); for(var i=0; i<=(urlVars.length); i++){ if(urlVars[i]){ var urlVarPair = urlVars[i].split('='); document.getVars[urlVarPair[0]] = urlVarPair[1]; } } } })(); prceptType = document.getVars.preceptType; document.write('<input type="hidden" name="preceptType" value='+preceptType+' />'); </script> <input type="submit" value="Submit" /> <input type="button" name="backButton" value="Back" onclick="parent.location = './welcome.html'" /> <input type="button" name="homeButton" value="Home" onclick="parent.location = '../index.html'" /></form> </div> </body> </html> I have modified a free JS function from he http://www.tangorangers.com/examples...post/index.php To dynamically add text fields to the form. My work-in-progress version is he http://jimpix.co.uk/junk/test/6.html On the form, I have a hidden text field: Code: <input type="hidden" name="hiddenCount" value="" /> What I'd like to do is to increment the hiddenCount each time the "Add" fields button is clicked. This is the button: <input id="add_contact()" onclick="add_contact()" value="Add" type="button"> And this is the JS function: Code: var contact_counter = 0; function add_contact() { if (contact_counter < 9) { contact_counter++; var newFields = document.getElementById('add_contact').cloneNode(true); newFields.id = 'contact'; newFields.style.display = 'block'; var newField = newFields.childNodes; for (var i=0;i<newField.length;i++) { var theName = newField[i].name if (theName) newField[i].name = theName + contact_counter; } var insertHere = document.getElementById('add_contact'); insertHere.parentNode.insertBefore(newFields,insertHere); } } I'm new to JS. I could just about edit the JS function to slightly modify it from the tangorangers version (I only changed it v. slightly). To somehow increment the value in the hidden field each time the button is pressed is beyond me though! Any advice much appreciated. Thanks 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. 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.. I 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, First off thank you for looking at my post. Please forgive me if I do something incorrectly here. I have never posted in a forum before. You are very kind to assist me in this problem. I wish to send the javascript calculated value in a form from one page to another page form. I just need the one value sent. The value is "answer: in the code below. I would like to send it to a form page called "answer.html" I am not a computer person, and I am doing this in frontpage. I do not know how to write java or anything, I just copied this from a free script site and am trying to use it. Thank you once again for your kindness and patience with me. Thanks to all you experts! Michael here is the code I have. --------------------------------------------- Code: <table cellspacing=0 width=427 height=1 bgcolor="#FFFFFF" style="border-collapse: collapse" cellpadding="0" border="0"> <tr> <td width="634" nowrap height="1"> <script language="JavaScript"> function findcalculatorcalculate(form) { a = form.debt.value - 0; b = form.faith.value - 0; d = a / b; form.answer.value = Math.round (d); }</script> <p align="right" style="margin-left: 3; margin-right: 5"></p> <form name="form" style=" margin-right: 5; padding-left: 4; padding-right: 4; padding-top: 1; padding-bottom: 1" action="--WEBBOT-SELF--" method="POST"> <p align="right"> <font style="font-size: 11pt; font-weight:700">Input amount <input class="regfont" size="13" type="text" name="debt"></font><span style="font-size: 11pt; font-weight:700"> <br> divide by </span><font style="font-size: 11pt; font-weight:700"><input class="regfont" size="6" type="text" name="faith"></font><br> <b><font color="#FF0000" size="5"> </font></b><font style="font-size: 11pt"><input onclick="findcalculatorcalculate(this.form)" value="CLICK HERE TO CALCULATE" type="button" style="border-style:solid; border-width:2; font-weight: bold; font-family:Arial"><br> <b>ANSWER</b> </font></font> <INPUT NAME="answer" SIZE="5" VALUE=""><br> <INPUT TYPE="BUTTON" onClick="nextpage()" VALUE="Go to the next page"></p> </p> </form> </td> </tr> </table> <p align="right" style="margin-left: 3; margin-right: 5">I would like ANSWER field to pre populate the calculated amount on the second page titled "answer.html" THANK YOU!</p> ------------------------ Thank you again for helping me in plain language because I do not have the skills that all of you do. 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. I need when I click to type into a form field, I need an onclick event to show another form field. I would assume this would be a hiddin div or an on click event to post another form field. So in theory just because I actually clicked into one form field...another form field shows up underneath it...can anyone help... |