JavaScript - Passing Checkbox Form Values Help, Having Issues With Passing Non-checked Value
Hello, i'm working on a 3 page survey. When hitting next, previous, or submit it passes the values of all the questions to the next page. I've got the whole thing working correcting except for one thing: When the box is "not" checked it passes no value. I'm needing it to have a value of "1" when checked and a value of "0" when not checked, and currently when its not checked and i pass the info it leaves it blank.
I'd post the whole code to one of the pages but it's long , so i'll post the snipits of the code. Code: <script type="text/javascript"> /* <![CDATA[ */ function processQueryString() { var formData = location.search; formData = formData.substring(1, formData.length); while (formData.indexOf("+") != -1) { formData = formData.replace("+", " "); } formData = unescape(formData); var formArray = formData.split("&"); for (var i=0; i < formArray.length; ++i) { //document.writeln(formArray[i] + "<br />"); var sDataName = formArray[i].split("=") switch (sDataName[0]) { case ".lib_use": for (var j=0; j < document.getElementsByName(".lib_use").length; ++j) { if (document.getElementsByName(".lib_use").item(j).value == sDataName[1]) { document.getElementsByName(".lib_use").item(j).checked = true; //alert("lib_use set"); } } break; case ".lib_comp": if (sDataName[1] == 1) { document.getElementsByName(".lib_comp").checked = true; document.getElementsByName(".lib_comp").value= 1; } else { document.getElementsByName(".lib_comp").checked = false; document.getElementsByName(".lib_comp").value= 0; } break; default: alert("not caught = " + sDataName[0]); continue; } } } /* ]]> */ </script> <input type="checkbox" name=".lib_comp" id="lib_comp" value="1" /> The first case that i showed in my code is a radio button, and it passes correctly, i just wanted to show the "format" i was using in a working sense. The 2nd case is an example of the check boxes. Thanks for looking at this, and giving any suggestions you might have! Similar TutorialsI have a signup form on a site that does a check on submission of fields to see if they populated and error box if not changes focus to missing field and highlights field name in red. I wanted to improve on its effectiveness as it only checks 2 fields atm and I wanted it to check some dynamic fields as well the fields are associative arrays generated via php as follows:- Code: echo "<select name='nfield[$t]'>\n"; for ($i = 0; $i<count($value2); $i++) { echo "<option value=\"".trim($value2[$i])."\">".trim($value2[$i])."</option>\n"; } echo "</select>"; the javascript is as follows:- Code: function checkForm() { //This is the name of the function if (Form1.password.value == "") { alert("Please enter a Password."); Form1.password.focus( ); document.getElementById('password').style.color="red"; return false; } The field is displayed via php as follows:- echo "<tr><td align='center' id='password'>Password:</td><td><input type='password' name='password' size='10'></td></tr>\n"; So i thought ah easy, i will just add the following checking javascript to check each of the associative arrays as they never change Code: if (Form1.nfield[1].value == "") { alert("Please choose an option for option1"); Form1.nfield["1"].focus( ); //This focuses the cursor on the problem field document.getElementById('nfield[1]').style.color="red"; return false; //This prevents the form from being submitted } if (Form1.nfield[2].value == "") { alert("Please choose an option for option2"); Form1.nfield[2].focus( ); //This focuses the cursor on the problem field document.getElementById('nfield[2]').style.color="red"; return false; //This prevents the form from being submitted } if (Form1.nfield[3].value == "") { alert("Please choose an option for option3"); Form1.nfield[3].focus( ); //This focuses the cursor on the problem field document.getElementById('nfield[3]').style.color="red"; return false; //This prevents the form from being submitted } but this doesn't work, i think it doesn't recognise the nfield[1] syntax, can a javascript guru point me in the right direction ? I also wanted to enhance the form somewhat as atm it only displays one error popup at a time, so if the user has missed out a few fields they will get an initial popup, try and submit again and then get the second popup for the other missing field. Can my code be modified to show a list of the missing fields and highlight all the titles in red (and if possible change the background colour of the input boxes or border the input fields in red etc)? I have a bunch of checkboxes like below that the user can check some or all and click the button and see the values of all the selected checkboxes. How can I do that? Code: <script> function alertValues(){ } </script> <input type="checkbox" class ="normal2" value="131971" name="list[]" > <input type="checkbox" class ="normal2" value="131973" name="list[]" > <input type="checkbox" class ="normal2" value="131975" name="list[]" > <input type="checkbox" class ="normal2" value="131977" name="list[]" > <input type="button" onClick="alertValues()" I was wondering if anyone could help me with getting this working. I'm using html to create a table which has at least 1 row but no max number of rows - as they can be added/removed by the user - and 4 columns, 1st contains a checkbox and the last 2 contain drop down menus. I wish to be able to store the values of those menus in an array only if that row's checkbox has been checked. e.g if the first row has 1 and A as it's dropdown values and the second row has 2 and B. If only row 1 has been checked the array should only contain [1,A]. Instead mine holds all the values including the non-checked ones i.e [1,A,2,B]. My code for javascript function and html table are below: Code: function calculate(textID){ var table = document.getElementById('course'); //id of table var rowCount = table.rows.length; var array = []; //array to hold the values var c = 0; dmenus = document.getElementByTagName("select"); //get the drop down menus for(var a = 1; a < rowCount; i++){ //a = 1 as the 1st row contains column headings var row = table.rows[a]; var check = row.cells[0].childNodes[0]; if(null != check && true == check.checked){ for(var b = 0; b < dmenus.length; b++){ val = dmenus[b].options[dmenus[b].selectedIndex].value; array[c] = val; //set index of array to equal value of dropdown box c++; } }else{ b++; } } Html code for table: Code: <table id="course"> <tr> <td><input type="checkbox" name="ucheck" id="ucheck" onclick="checkAll('course')"/></td> <th style="color:white">Course Title</th> <th style="color:white">Credits</th> <th style="color:white">Grade</th> </tr> <tr> <td><input type="checkbox" name="tick" id="tick"/></td> <td><input type="text"/></td> <td> <select name="credits" id="credits"> <option...</select></td> <td> <select name="grade" id="grade"> <option...</td> It works only for the first row but if there are more than 1 row it doesn't do what it's supposed to. The coding platform I'm working on does not seem to support jquery so javascript code will be most appreciated. Thanks Hi, I was wondering if i can pass my php variables through javascript function. Actually i have a simple table of pictures, when clicked in the picture a new popup page comes up, it working fine uptill this stage but now i want to pass a value through it, for instance if user clicks on picture1 then my popup url should be "item_large.php?id=pic1 My Javascript junction for the popup window: Code: function popup() { window.open("item_large.php","Register","menubar=no,width=500,height=400,toolbar=no"); } My Html code where i have my pictures: Code: <td height="19" align="center" valign="top" onmouseover="this.bgColor='#CC3300' ; this.style.cursor='pointer'" onmouseout="this.bgColor='#FFFFFF'" <A HREF="javascript:popup()">Picture01</A> </td> Thanks I have the following snippet of HTML code: Quote: <table id="identificativo"> .......... .......... .......... <tr id="id_riga"> <td width="40%"> Cella 1 </td> <td> <input type="hidden" name="params" value="valore1 valore2" /> <input type="button" value="Add/Change" onclick="return del()" /> </td> <td> Cella3 </td> </tr> ............ ............ ............ and the following javascript code that replace the second row of table with new form: Quote: function del() { if (document.getElementById) { var tabella = document.getElementById("identificativo"); tabella.deleteRow(1); x = tabella.insertRow(1); x.innerHTML = "<td colspan='3'> \ <form action='/cgi-bin/save.cgi' method='POST'> \ <input type='text' name='name' size='30' /> \ <input type='submit' value='Save' /> \ </form> \ </td>"; } } How can to pass hidden values valore1 and valore2 from old cell of row to new form with javascript? Thank you in advance to answers, savio Hi, I am trying to pass a video id value from one javascript page to another, extract the video id, append it to a utube url and then pass it to a html page for immediate display. I have managed to extract the video id value and append it to the url but cannot get it into the html section of the code. My code is posted below <html> <head> <script type="text/javascript"> function getParams() { var idx = document.URL.indexOf('?'); var urlId; var params = new Array(); if (idx != -1) { var url = document.URL.substring(idx+1, document.URL.length).split('&'); for (var i=0; i<url.length; i++) { videoVal = url[i].split('='); urlId = "http://www.youtube.com/v/" + videoVal[1]; } } document.getrElementById('UrlId').value=urlId; } params = getParams(); </script> </head> <body> <object width="425" height="344"> <param name="UrlId" value=urlId; </param><embed src=urlId type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"> </embed> </object> </p> </body> </html> I need to get it to appear as a complete url in the following lines in the html code <param name="UrlId" value=urlId; <embed src=urlId type="application/x-shockwave-flash"></embed> Can someone please help with this. Thanks I want to pass dynamic array values to java script function.how its possible. explain with some code.........
i have this frameset: http://www.mediafire.com/?75dvswgvelw19a9 this is somehow the like my other posts but im dealing with the radio buttons. what i want is when i click on the "create" button in form1 http://www.mediafire.com/?eld7a1rb21h799e it will pass the value to form 2 http://www.mediafire.com/?f0o060cdpyf06ya. so when i select "yes" in form1 and click on "create" it will autoselect "On" in form2. if i select "no" in form1 and click on "create" it will autoselect "off" in form2. I tried implementing a cleaner approach to a web form I had created, but it doesn't seem to be passing the values to the server properly. What gives? This form on the left and right work perfectly, but they have two ridiculously long drop down lists, which would be the "ProgramOfInterest" fields (please use the following values preselected in this form) http://www.nationalcollegesearch.org..._pingpost.html On this form, I tried creating a triple drop down list setup to clean up the older, long lists in this example, but it doesn't pass the values properly. It also seems to not duplicate the new drop down triple drop lists properly as in the original form. You can change the values in the drop downs in the forms to see what I mean. Also just pick Bachelor's > B_Business > Business Administration in the triple drop downs for an example since I don't know how to preselect those values. http://nationalcollegesearch.org/Integrate/PleaseHelpMeWithMyCode/integrate_pingpost_experiment.html Please let me know if there is anything I can do to pass the correct values to the server. Thanks! P.S. Please note that I have disabled the form on the right and intentionally left the action empty. This is the triple drop down script I am using: Code: <script type="text/javascript"> /* Triple Combo Script Credit By Philip M: http://www.codingforums.com/member.php?u=186 Visit http://javascriptkit.com for this and over 400+ other scripts Modified by: jmrker */ var categories = []; categories["startList"] = ["Diploma/Certificate:CE","Associate's:AA","Bachelor's:BA","Master's:MA"]; categories["Diploma/Certificate"] = ["C_Arts & Humanities:CE1","C_Automotive:CE2","C_Computers & IT:CE3","C_Education & Teaching:CE4","C_Health & Medical:CE5","C_Trades & Careers:CE6"]; categories["C_Arts & Humanities"] = ["Desktop Publishing:CEDP","Floral Design:CEFD","General Arts:CEGA","Interior Decorating:CEID","Jewelry:CEJ"]; categories["C_Automotive"] = ["Automotive Technician Training:CAUTO","Collision and Auto Body Repair:CCOLL","Motorcycle Mechanic Training:CMM"]; categories["C_Computers & IT"] = ["Cisco:CECS", "Information Technology:CEIT", "Microsoft:CEMS", "Network Systems:CENSYS", "Oracle:CEOR", "PC Repair:CEPC"]; categories["C_Education & Teaching"] = ["Child Day Ca CEDC", "General Education:CEGE"]; categories["C_Health & Medical"] = ["Dental Assisting:CEDENT", "Fitness:CEFIT", "Healthca CEHC", "Massage Therapy:CMT", "Medical Assisting:CEMEA", "Medical Billing and Insurance Coding:CEMBIC", "Medical Office Administration:CEMOA", "Occupation Therapy:CEOT", "Phlebotomy:CEPHL", "Social Work:CESW"]; categories["C_Trades & Careers"] = ["Administrative Assistant:CEAA", "Animal Ca CEAC", "Appliance Repair:CEAR", "Bookkeeping and Payroll Accounting:CEBOO", "Bridal Consulting:CEBC", "Carpentry and Construction:CECC", "Culinary:CECU", "Drafting:CEDR", "Electronics:CEEL", "Forestry and Wildlife:CEFW", "Gunsmithing:CEGUN", "HVAC:CEHV", "Landscaping:CELS", "Law Enforcement:CELE", " Locksmithing:CELOCK", "Plumbing and Electrical:CEPE", "Private Investigator:CEPI", "Wedding Planner:CEWP"]; categories["Associate's"] = ["A_Arts & Humanities:AA1","A_Business:AA2","A_Criminal Justice:AA3","A_Computers & IT:AA4","A_Education & Teaching:AA5","A_Health & Medical:AA6","A_Science & Technology:AA7","A_Social Sciences:AA8","A_Trades & Careers:AA9"]; categories["A_Arts & Humanities"] = ["Communication:AACOM","Fashion:AAFASH","Game Design:AAGD","General Arts:AAGA","Graphic Design:AAGR","Religion:AAREL","Web Design:AAWD","Writing:AAWR"]; categories["A_Business"] = ["Accounting:AAAC","Administrative Assistant:AAAS","Business Administration:AABA","eBusiness and eCommerece:AAEB","Finance:AAFIN","Human Resources Management:AAHR","International Business:AAIB","Marketing:AAMAR","Organizational Leadership:AAOR","Project Management:AAPM"]; categories["A_Criminal Justice"] = ["Criminal Justice:AACJ","Homeland Security:AAHS","Law:AALAW","Legal Assisting Paralegal:AAPAR","Political Science:AAPS"]; categories["A_Computers & IT"] = ["Computer Networking and Security:AACNS","Computer Science:AACS","Databases:AADB","Information Systems:AAIS","Information Technology:AAIT","Technology Management:AATEM","Web Development:AADEV"]; categories["A_Education & Teaching"] = ["Adult and Higher Education:AAHE","Curriculum and Instruction:AACI","Early Childhood Education:AAEVE","General Education:AAGE","Special Education (K-12):AASE"]; categories["A_Health & Medical"] = ["Gerontology (Study of people as they age):AAGER","Healthca AAHLTH","Healthcare Management:AAHCM","Medical Assisting:AAMA","Medical Billing and Insurance Coding:AAMBIC","Medical Office Administration:AAMOA","Nursing:AANUR","Radiology & Sonography:AARAD"]; categories["A_Science & Technology"] = ["Aviation:AAAV","Engineering Management:AAEN","Environmental Sciences:AAENV","Science:AASCI"]; categories["A_Social Sciences"] = ["Counseling:AACOUN","History:AAHIST","Psychology:AAPSY","Public Administration:AAPA","Public Safety:AAPUBS","Social Science:AASS"]; categories["A_Trades & Careers"] = ["Animal Ca AAAC","Carpentry & Construction:AACAR","Fire and Law Enforcement:AALE","Travel and Tourism:AATR"]; categories["Bachelor's"] = ["B_Arts & Humanities:BA1","B_Business:BA2","B_Computers & IT:BA3","B_Criminal Justice:BA4","B_Education & Teaching:BA5","B_Health & Medical:BA6","B_Science & Technology:BA7","B_Social Sciences:BA9","B_Trades & Careers:BA0"]; categories["B_Arts & Humanities"] = ["Communication:BACOM","Fashion:BAFASH","Game Design:BAGD","General Arts:BAGA","Graphic Design:BAGR","Music:BAMUS","Religion:BAREL","Web Design:BAWD","Writing:BAWR"]; categories["B_Business"] = ["Accounting:BAAC","Business Administration:BABA","eBusiness and eCommerece:BAEB","Entrepreneurial Studies:BAES","Finance:BAFIN","Human Resources Management:BAHR","International Business:BAIB","Marketing:BAMAR","Organizational Leadership:BAOR","Project Management:BAPM"]; categories["B_Computers & IT"] = ["Computer Networking and Security:BACNS","Computer Science:BACS","Databases:BADB","Information Systems:BAIS","Information Technology:BAIT","Technology Management:BATM","Web Development:BADEV"]; categories["B_Criminal Justice"] = ["Criminal Justice:BACJ","Homeland Security:BAHS","Law:BALAW","Legal Assisting Paralegal:BAPAR","Political Science:BAPS"]; categories["B_Education & Teaching"] = ["Adult and Higher Education:BAHE","Curriculum and Instruction:BACI","Early Childhood Education:BAECE","General Education:BAGE","Special Education (K-12):BASE"]; categories["B_Health & Medical"] = ["Gerontology (Study of people as they age):BAGR","Healthca BAHLTH","Healthcare Management:BAHCM","Medical Assisting:BAMA","Nursing:BANUR","Radiology & Sonography:BARAD"]; categories["B_Science & Technology"] = ["Aviation:BAAV","Electronics Engineering:BAEE","Engineering Management:BAEN","Environmental Sciences:BAENV","Mathematics:BAMS","Science:BASCI"]; categories["B_Social Sciences"] = ["Counseling:BACOUN","History:BAHIST","Psychology:BAPSY","Public Administration:BAPA","Public Safety:BAPUBS","Social Science:BASS","Sociology:BASOC"]; categories["B_Trades & Careers"] = ["Fire and Law Enforcement:BALE"] categories["Master's"] = ["M_Arts & Humanities:MA1","M_Business:MA2","M_Computers & IT:MA3","M_Criminal Justice:MA4","M_Education & Teaching:MA5","M_Health & Medical:MA6","M_Science & Technology:MA7","M_Social Sciences:MA9"]; categories["M_Arts & Humanities"] = ["Communication:MACOM","Game Design:MAGD","General Arts:MAGA","Graphic Design:MAGR","Music:MAMUS","Religion:MAREL","Web Design:MAWD","Writing:MAWR"]; categories["M_Business"] = ["Accounting:MAAC","Business Administration:MBA","eBusiness and eCommerece:MAED","Entrepreneurial Studies:MAES","Finance:MAFA","Finacial Planning:MAFPL","Human Resources Management:MAHR","International Business:MAIB","Marketing:MAMAR","Organizational Leadership:MAOR","Project Management:MAPM"]; categories["M_Computers & IT"] = ["Computer Networking and Security:MACNS","Computer Science:MACS","Databases:MADB","Information Systems:MAIS","Information Technology:MAIT","Technology Management:MATM","Web Development:MADEV"]; categories["M_Criminal Justice"] = ["Criminal Justice:MACJ","Homeland Security:MAHS","Law:MALAW","Legal Assisting Paralegal:MAPAR","Political Science:MAPS"]; categories["M_Education & Teaching"] = ["Adult and Higher Education:MAHE","Curriculum and Instruction:MACI","Early Childhood Education:MAECE","General Education:MAGE","Special Education (K-12):MASE"]; categories["M_Health & Medical"] = ["Gerontology (Study of people as they age):MAGR","Healthca MAHLTH","Healthcare Management:MAHCM","Medical Assisting:MAMA","Nursing:MANUR","Radiology & Sonography:MARAD"]; categories["M_Science & Technology"] = ["Aviation:MAAV","Electronics Engineering:MAEE","Engineering Management:MAEN","Environmental Sciences:MAENV","Mathematics:MAMS","Science:MASCI"]; categories["M_Social Sciences"] = ["Counseling:MACOUN","History:MAHIST","Psychology:MAPSY","Public Administration:MAPA","Public Safety:MAPUBS","Social Science:MASS","Sociology:MASOC"]; var nLists = 3; // number of select lists in the set function fillSelect(currCat,currList){ var step = Number(currList.id.replace(/\D/g,"")); for (i=step; i<nLists+1; i++) { document.forms['form1']['List'+i].length = 1; document.forms['form1']['List'+i].selectedIndex = 0; } var tmp = currCat.split(':'); var nCat = categories[tmp[0]]; for (each in nCat) { tmp = nCat[each].split(':'); var nOption = document.createElement('option'); var nData = document.createTextNode(tmp[0]); nOption.setAttribute('value',nCat[each]); nOption.appendChild(nData); currList.appendChild(nOption); } } function getValue(L3, L2, L1) { var l3 = L3.split(':'); var l2 = L2.split(':'); var l1 = L1.split(':'); // alert("Your selection was:- \n" + L1 + "\n" + L2 + "\n" + L3); // alert("Your selection was:- \n" + l1[1] + "\n" + l2[1] + "\n" + l3[1]); } function init() { fillSelect('startList',document.forms['form1']['List1']) } navigator.appName == "Microsoft Internet Explorer" ? attachEvent('onload', init, false) : addEventListener('load', init, false); </script> </head> <body> <form name="form1" action=""> <table> <tr> <td class="frmText" style="color: #000000; font-weight: normal;">Degree:</td> <td><select id='List1' onchange="fillSelect(this.value,this.form['List2'])"> <option selected>Select degree</option> </select> </td> </tr> <tr> <td class="frmText" style="color: #000000; font-weight: normal;">Area of Study:</td> <td><select id='List2' onchange="fillSelect(this.value,this.form['List3'])"> <option selected>Select area of study</option> </select> </td> </tr> <tr> <td class="frmText" style="color: #000000; font-weight: normal;">Program of Interest:</td> <td><select class="frmInput" id="List3" name="ProgramOfInterest" onchange="getValue(this.value,this.form['List2'].value, this.form['List1'].value)"> <option selected >Select program</option> </select> </td> </tr> </table> </form> Hello guys. I've been struggling on how to make this work. I have a problem in Javascript when it comes to passing of value in a input type field. page1.html Code: <html> <head><title></title></head> <form action="" method="post> <input type="text" name="weight" value=""><a href="hw_calculator.html" target="name" onclick="window.open('hw_calculator.html','name','height=270,width=370,toolbar=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes'); return false;"> calculate </a> </form> </html> hw_calculator.html Code: <html> <head> <title> Height Converter (Metric/Standard) </title> </head> <body> <FORM> <INPUT type=hidden value="(Math.round((P.value * 0.45359)*100))/100" name=K_expr> <INPUT type=hidden value="(Math.round((K.value / 0.45359)*100))/100" name=P_expr> <INPUT type=hidden value="(Math.round((F.value * 30.48 + I.value * 2.54)*100))/100" name=C_expr> <INPUT type=hidden value="(Math.floor(C.value / 30.48))" name=F_expr> <INPUT type=hidden value="(Math.round(((C.value - (Math.floor(C.value / 30.48) * 30.48)) / 2.54)*100))/100" name=I_expr> <INPUT type=hidden value="(Math.round(P.value * 0.45359))" name=K_exprrnd> <INPUT type=hidden value="(Math.round(K.value / 0.45359))" name=P_exprrnd> <INPUT type=hidden value="(Math.round(F.value * 30.48 + I.value * 2.54))" name=C_exprrnd> <INPUT type=hidden value="(Math.floor(C.value / 30.48))" name=F_exprrnd> <INPUT type=hidden value="(Math.round((C.value - (Math.floor(C.value / 30.48) * 30.48)) / 2.54))" name=I_exprrnd> <h2>Height Converter</h2> <table border="0" bgcolor="#FFFF99" cellspacing="6" cellpadding="6"> <tr> <td colspan> <p class="conv" style="margin-top: 10px; margin-bottom: 10px"><b>STANDARD</b></p> </td> <td></td> <td colspan> <p class="conv" style="margin-top: 10px; margin-bottom: 10px"><b>METRIC</b></p> </td> </tr> <tr> <td> <p class="conv" style="margin-top: 10px; margin-bottom: 10px">Feet : <input maxLength=1 size=1 value=0 name=F> Inches : <input maxLength=2 size=1 value=0 name=I> </td> <td> <p class="conv" style="margin-top: 10px; margin-bottom: 10px"> = </p> </td> <td> <p class="conv" style="margin-top: 10px; margin-bottom: 10px"><input maxLength=3 size=1 value=0 name=C disabled> cm.</p> </td> </tr> <tr> <td class="conv" colspan="2"> <input type="button" name="Taste" value="Calculate" onclick="if (rounded.checked == true) { eval('C.value = ' + this.form.C_exprrnd.value); eval('K.value = ' + this.form.K_exprrnd.value) } else { eval('C.value = ' + this.form.C_expr.value); eval('K.value = ' + this.form.K_expr.value) }"> <INPUT type=checkbox name="rounded" value="rounded" checked disabled><font size="1" face="Verdana">Rounded Result</font> </td> </tr> </table> <p class="conv" style="margin-top: 10px; margin-bottom: 10px"> </body> </html> I want the value of Code: <input maxLength=3 size=1 value=0 name=C disabled> , this is from hw_calculator.html, to be passed on the Code: <input type="text" name="weight" value=""> on page1.html. How can I do this? Huge thanks. Dear all, I'm passing the variables myTitle and myLink to form.php using javascript. This is the way I'm doing it: Code: <a href='form.php?title=" + myTitle +"&link="+myLink+">Click me</a> It's working great but sometimes myTitle and myLink contain the plus character (+). When this happens it's not passed. In the case of the title, it's just a problem of looks but in the case of the link, well, the link won't work without the character. As an example if the title is: Laptop + Accessories What is passed is: Laptop Accessories What can I do to pass also the plus character?? Thanks a lot!! Hi, I have what I assume started as a simple error and then trying to fix it I think I have made things so complicated I've become confused. I have two fields, a drop down list and a text field, when someone clicks on a value in a drop down list (I will show the results eventually but at the moment) I just want the result to echo in my getCategory.php and the same for the text field. Both php pages are currently being called. And at the moment contain $_REQUEST['category'] and $_REQUEST['ProductName'] respectively. Nothing is being echoed. I know the below code is wrong, but the more I try to correct it the worse it gets so I thought I would just leave it as is before I made it worse. Code: <script type="text/javascript"> function loadXMLDoc1(File,ID,Msg){ if (window.XMLHttpRequest) { xmlhttp=new XMLHttpRequest(); } else { try{ xmlhttp=new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } } xmlhttp.onreadystatechange=function(){ if (xmlhttp.readyState==4 && xmlhttp.status==200){ document.getElementById(ID).innerHTML=xmlhttp.responseText; } } var params=Msg; xmlhttp.open("POST",File,true); xmlhttp.setRequestHeader("Pragma", "Cache-Control:no-cache"); xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); xmlhttp.setRequestHeader("Content-length", params.length); xmlhttp.setRequestHeader("Connection", "close"); xmlhttp.send(params); } </script> </head> <body> <label>Search by Category: </label> <select name="category" id="category" onchange='loadXMLDoc1("getCategory.php","txtHint","category")' class="input"> <option value="please select" selected"selected">Please Select</option> <option value="Clothes" name="Clothes" id="Clothes">Clothes</option> <option value="Bags" name="Bags" id="Bags">Bags</option> <option value="Hats" name="Hats" id="Hats">Hats</option> </select> <br /> <br /> <label>Search by name: </label> <input type="text" class="input" name="ProductName" id="ProductName" value="Search" size="30"/> <input type="button" value="Search" onclick="loadXMLDoc1('getProductName.php','txtHint', ProductName='(this.value)')" /> <br /> <br /> <div id="txtHint"></div> I need to style a checkbox, so I made it into two images behind a form with hidden inputs. On click the form takes input from the other form into the hidden fields and POSTs it. Then I use PHP to grab that POST and put it back into the original form. Here are some snippets of what I am trying to do: First form input: PHP Code: <input type="text" name="email" id="email1" value="<?php if(isset($_POST['email2'])) { echo $_POST['email2']; } ?>" style="height:25px;width:270px;" /> Second form input: PHP Code: <input type="hidden" name="email2" id="email2" /> Second form submit image button: PHP Code: <input type="image" src="img/Boxchecked.jpg" value="submit" onclick="fname2.value = fname1.value; lname2.value = lname1.value; email2.value = email1.value" width="20" height="20" /> The forms work fantastic on everything but IE, which does not save the field values. How do I fix the onclick event to save them in IE? Help is much appreciated. Hi, I am quite new to javascript but I'm quite sure this problem is very easy to solve. I have a vague idea of what might be going wrong but I have no idea what I should be doing instead. Here is what I'm trying to do: User inputs X and Y coordinates into form validate that they are numbers do a little bit of maths redirect to a php script with a single variable tacked onto the end of the url Here is the form code: Code: //part of a larger php script to make the form echo "<form name='gotoForm' onsubmit='return coordCalc()'> <fieldset> <legend>Go to Square</legend> X <input type='text' id='X' size='1' maxlength='3'/> Y <input type='text' id='Y' size='1' maxlength='3'/> <input type='submit' value='Go To' /> </fieldset> </form> "; which references these functions in the header: Code: //Is it a number function isNumeric(elem, helperMsg){ var numericExpression = /^[0-9]+$/; if(elem.value.match(numericExpression)){ return true; }else{ alert(helperMsg); elem.focus(); return false; } } //deal with the input, check if they are both numbers with the above function //if they are do some maths on the input //add the result onto a url and redirect function coordCalc (){ var Xcoord = document.getElementById('X'); var Ycoord = document.getElementById('Y'); if(isNumeric(Xcoord, "Please enter a Number for X")){ if(isNumeric(Ycoord, "Please enter a Number for Y")){ //Takes the X and Y coordinates and transforms them into a single number //not fully coded in case you try putting some numbers into the formula btw :) var X = parseInt(document.getElementById('X').value); var Y = parseInt(document.getElementById('Y').value); var G = 16; var Z = (((G + 1) - Y) - Y); var A = (Y + Z); var B = (X - 1); var L = ((A * (G - 1)) + B); window.location = "map.php?start=" + L; } } return false; } The number validation works but the url ends up as map.php?start=NaN. Now, this simply must be the way I am assigning the Xcoord and Ycoord variables with the document.getElementByID() function I am sure. But like I said, I have no idea what to do instead, any help is massively appreciated. Thankyou! Hi, I've had problems in the past understanding this, however, after reading this tutorial, I understand. In some languages, like VB6, I notice the "byVal" and the "byRef" is specifically used. In javascript, I don't notice those specifics typed in functions. Is the "default" by value when using in a function to change a parameter? If it is, what is the syntax for using by reference, or is that ever used? My question arises from this notation taken from here: Quote: Note that it is the value that a has at the time that it is passed into the function that gets substituted into the argument and not the value that the original variable has at that point in the processing. It is the values in the parameters that the function uses and not the variables. This is called pass by value . In those languages where you can pass the actual variable into the function instead of just passing its value the method used to do so is called pass by reference . Had we been able to pass the variables into the function by reference rather than by value then the final value in b would have been -16 instead of -14. Here is the example (passing by value): Code: function myfunction(y, z) { a += y; b -= z; } var a = 0; var b = 10; var c = 3; var d = 4; var e = 2; myfunction(c, d); myfunction(d, e); myfunction(9, 2); myfunction(b, a); Results: myFunction(c, d); output: 0 + 3 = 3(y), 10 - 4 = 6(z) myFunction(d, e); output: 3 + 4 = 7(y), 6 - 2 = 4(z) myFunction(9, 2); output: 7 + 9 = 16(y), 4 - 2 = 2(z) myFunction(b, a); output: 2 + 16 = 18(y), 2 -16 = -14(z) Thanks! hi there, i'm new here and pretty new to js. i'm making a page for my daughter's school - or trying to. they are having a silent auction and i'm trying to make a very simple bidding page. where i'm running into problems is passing the bid to a text box (read only) where it can be updated when a new bid is entered. I would like this to be in the upper part of the page with the listings of the auction items, i just can't wrap my head around how to do this. I've gotten as far as the form for entering the bod and contact info. I have the php code to submit. i still have to get the validation js to make it more secure. thanks for any help. Code: <html> <body> <h1 id="logo"></h1> <div id="main"> <p> <h4>Silent Auction</h4> <form name="auction" method="post" action="send_form_email.php" > <label for="item1">Item 1</label> <br /> <label for="curr_bid_item_1">Current Bid = </label><br /> Your Bid = <input type="text" name="item1" maxlength="15" size="10" /> <br /> <br /> <label for="item2">Item 2</label><br /> <label for="curr_bid_item_2">Current Bid = </label><br /> Your Bid = <input type="text" name="item2" maxlength=="15" size="10" /> <br /> <br /> <label for="item3">Item 3</label><br /> <label for="curr_bid_item_3">Current Bid = </label><br /> Your Bid = <input type="text" name="item3" maxlength="15" size="10" /> <br /> <br /><br /><br /> <form name="contactform" method="post" action="send_form_email.php" onsubmit="document.getElementById('myButton').disabled=true; document.getElementById('myButton').value='Submitting, please wait...';"> <label for="first_name">First Name *</label> <input type="text" name="first_name" maxlength="50" size="30"><br /><br /> <label for="last_name">Last Name *</label> <input type="text" name="last_name" maxlength="50" size="30"><br /><br /> <label for="email">Email Address *</label> <input type="text" name="email" maxlength="80" size="30"><br /><br /> <label for="telephone">Telephone Number</label> <input type="text" name="telephone" maxlength="30" size="30"><br /><br /> <label for="comments">Comments</label><br /> <textarea name="comments" maxlength="1000" cols="40" rows="6"></textarea><br /><br /> <input type="submit" value="Submit" id="myButton" /> </form> </form> </div> </body> </html> I inherited a calculator form using javascript that passes the form field data to a "lead mailbox" .asp page on a different site, and that site would then email/forward the salesman the data. The calculator also passes the calculated data to the next page for the user and gives them their calculated loan range. What I would like to do is not send this data to the "lead mailbox" site but instead send the data via Gmail (if possible) to the salesman as he wants to generate leads outside the company and not use the "lead mailbox". There are two lines of code that specify where to send the data (to the "lead mailbox" site) but I don't know how the receiving page is setup to receive the form data fields as it is https: (SSL) and I don't have access to that code. Everything works perfect with the code...I just want to send the data to a new location...but not sure how or if I can pass the data fields to a Gmail account like the salesman would like. Thanks for any help you can provide!! Normally sending form data is easy...but I inherited this and it was custom written javascript. Code: {document.contact.action = "https://www.othersitemailbox.com/post.aspx?account=EXN01&source=PTPPC-QQ"; document.contact.landing.value = "http://www.best-mortgage-programs.com/QQ.html?"+link} I have "blurred/changed" out the actual landing page value and actual URL of the https: address for privacy reasons... Thanks!! |