JavaScript - Form With Add Row And Disable Not Working
I'm new at JavaScript and not sure if what I want to do is possible. This is part of the code from a larger check-in form.
This code adds a new row as needed and should also enable the text fields only after the check box is selected. It is not working as expected and I am missing what the problem may be or if this is even possible. Any help would be appreciated. [CODE] <!DOCTYPE html> <html lang="en"> <title></title> <script type="text/javascript"><!-- function addRow() { tabBody=document.getElementById("data"); row=document.createElement("TR"); cell1 = document.createElement("TD"); checknode1 = document.createTextNode("\u00a0\u00a0\u00a0\u00a0"); checknode2 = document.createElement("input"); checknode2.name="guest[]"; checknode2.id='guest[]'; checknode2.type="checkbox"; checknode2.setAttribute('onclick', 'disablefields();'); cell2 = document.createElement("TD"); textnode1 = document.createTextNode("\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0"); textnode2=document.createElement("input"); textnode2.type="text"; textnode2.name='guestc[]'; textnode2.id='guestc[]'; textnode2.setAttribute('disabled',''); textnode2.size="7"; textnode2.maxlength="9"; textnode2.setAttribute('onkeyup', 'this.value = this.value.toUpperCase();'); cell3 = document.createElement("TD"); textnode3=document.createElement("input"); textnode3.type="text"; textnode3.name="guestn[]"; textnode3.id='guestn[]'; textnode3.setAttribute('disabled',''); textnode3.size="20"; textnode3.maxlength="30"; cell4 = document.createElement("TD"); checknode3 = document.createTextNode("\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0"); checknode4 = document.createElement("input"); checknode4.name="food[]"; checknode4.id='food[]'; checknode4.type="checkbox"; checknode4.value="breakfast"; cell1.appendChild(checknode1); cell1.appendChild(checknode2); row.appendChild(cell1); tabBody.appendChild(row); cell2.appendChild(textnode1); cell2.appendChild(textnode2); row.appendChild(cell2); tabBody.appendChild(row); cell3.appendChild(textnode3); row.appendChild(cell3); tabBody.appendChild(row); cell4.appendChild(checknode3); cell4.appendChild(checknode4); row.appendChild(cell4); tabBody.appendChild(row); } --> </script> <SCRIPT LANGUAGE="JavaScript"> <!-- function disablefields(){ if (document.getElementById('guest[]').checked == 0){ document.getElementById('guestc[]').disabled='disabled'; document.getElementById('guestc[]').value=''; document.getElementById('guestn[]').disabled='disabled'; document.getElementById('guestn[]').value=''; document.getElementById('food[]').disabled='disabled'; document.getElementById('food[]').value=''; }else{ document.getElementById('guestc[]').disabled=''; document.getElementById('guestc[]').value='Call Sign'; document.getElementById('guestn[]').disabled=''; document.getElementById('guestn[]').value='Enter Name'; document.getElementById('food[]').disabled=''; document.getElementById('food[]').value='breakfast'; } } --> </SCRIPT> </head> <body> <form name="checkin" method="post"> <table> <tbody id="data"> <tr><td> <input type="checkbox" name="guest[]" id="guest" onclick="disablefields()"></td> <td> <input type="text" disabled name="guestc[]" id="guestc[]" size="7" maxlength="9" value="" onkeyup="this.value = this.value.toUpperCase();" /></td> <td><input type="TEXT" name="guestn[]" disabled id="guestn[]" size="20" maxlength="30" value=""></td> <td> <input type="checkbox" name="food[]" disabled id="food[]" value="breakfast"></td></tr> </tbody> </table> <table border="0" width="100%"> <tr> <td><input type="button" value="Add new check-in" onclick="addRow();" /></td> </tr> </table> </form> </body> </html> [CODE] Similar TutorialsI'm trying to enable/disable a textarea. I am able to do a mouseout disable, but cannot do a mouseover enable. For instance, when I click on the image, a textarea shows up. When I move my mouse to a different location, the textarea disables fine. Then when I try to move my mouse back over the textarea, it DOES NOT enable for me to write in it. What am I doing wrong? Thanks! Another bonus question, I just happen to try out this code in IE and the textareas are not showing up where I click. I assume that I'm capturing the X/Y coordinates incorrectly for an IE browser. Any pointers? ********* CODE ************* <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>Mouse position</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <script type="text/javascript"> var posx, posy; // initialize cache var cache= []; var count=0; function getMouse(e){ posx= posy= 0; var ev= (!e) ? window.event : e;//IE:Moz if (ev.pageX){//Moz posx=ev.pageX+window.pageXOffset; posy=ev.pageY+window.pageYOffset; } else if(ev.clientX) {//IE posx=ev.clientX+document.body.scrollLeft; posy=ev.clientY+document.body.scrollTop; } else { // old browsers return false; } } function showP(){ // object to store this coordinate var thisCoord= {}; // x & y values stored as object attributes thisCoord.posx= posx; thisCoord.posy= posy; // check the cache for this coordinate object if ( !cache[thisCoord] ) { // if it hasn't been cached yet, push it onto the stack cache.push(thisCoord); var newDiv= document.createElement("textarea"); newDiv.setAttribute("class","div3"); newDiv.setAttribute("id",count); newDiv.style.width='180px'; newDiv.style.height='45px'; newDiv.style.visibility="visible"; newDiv.style.top= (thisCoord.posy -10) +'px'; newDiv.style.left= (thisCoord.posx -6) +'px'; newDiv.setAttribute("onmouseout","this.disabled=true"); newDiv.setAttribute("onmouseover","this.disabled=false"); // append to the document BODY document.getElementsByTagName("body")[0].appendChild(newDiv); count++; } } </script> <style type="text/css"> .div1 {position:absolute;top:100px;left:100px;visibility:visible;z-index:5} .div2 {position:absolute;top:0px;left:0px;visibility:hidden;z-index:1;color:black;} .div3 {position:absolute;visibility:hidden;z-index:10;font-size:14px;font-weight:450;color:black;} textarea[disabled='disabled'] { background:yellow; color:blue; cursor:default; } </style> </head> <body> <div id="div1" class="div1"> <img id="theImage" src="./YourImage.jpg"> </div> <script type="text/javascript"> // setup event handlers // document BODY onmousemove document.getElementsByTagName("body")[0].onmousemove= function(e){ getMouse(e); }; // the image onclick document.getElementById("theImage").onclick= showP; //onMouseOut </script> </body> </html> Guys Need Help here... here i send attach my script. i need combine 2 function script into . but i can figure it out. can everyone helps me. Code: <?php require_once('../Connections/koneksi.php'); ?> <!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> <script> function addRow(tableID) { var table = document.getElementById(tableID); var rowCount = table.rows.length; var row = table.insertRow(rowCount); var colCount = table.rows[0].cells.length; for(var i=0; i<colCount; i++) { var newcell = row.insertCell(i); newcell.innerHTML = table.rows[0].cells[i].innerHTML; switch(newcell.childNodes[0].type) { case "text": newcell.childNodes[0].value = ""; break; case "checkbox": newcell.childNodes[0].checked = false; break; case "select-one": newcell.childNodes[0].selectedIndex = 0; break; } } } function deleteRow(tableID) { try { var table = document.getElementById(tableID); var rowCount = table.rows.length; for(var i=0; i<rowCount; i++) { var row = table.rows[i]; var chkbox = row.cells[0].childNodes[0]; if(null != chkbox && true == chkbox.checked) { if(rowCount <= 1) { alert("Cant delete all rows"); break; } table.deleteRow(i); rowCount--; i--; } } }catch(e) { alert(e); } } function selectnama() { var i = 0; i = document.form1.txtcustomer.value; i= i.replace(/^[\s]+/,'').replace(/[\s]+$/,'').replace(/[\s]{2,}/,' '); //alert(cust[i]); document.form1.select2.value = i; } function change2() { document.form1.txtcustomer.value = document.form1.select2.value; } function enable_text(status) { status=!status; document.form1.qty_material.disabled = status; } </script> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <form name="form1" method="post" > <table id="dataTable" width="auto" style="margin:-4px 0 0 0;" cellspacing="6"> <tr> <td style="width:20px;"><INPUT type="checkbox" name="chk" /></td> <td> <input type="text" name="txttipe[]" placeholder="Tipe" id="txttipe" size="40"/> / <input name="txtcustomer" type="text" id="txtcustomer" onkeyup="selectnama()" size="10" maxlength="10"/> <select name="select2" style="color:blue;" onchange="change2()" > <option></option> <?php $query = mysql_query("select right(KUNNR,6), NAME1 from kna1 order by NAME1") or die(mysql_error()); $query3 = mysql_query("select * from spg_kna1_exception order by NAME1") or die(mysql_error()); while($row = mysql_fetch_array($query)) { echo "<option value=".$row[0].">$row[1] - $row[0]</option>"; } while($row3 = mysql_fetch_array($query3)) { echo "<option value=".$row3[0].">$row3[1] - $row3[0]</option>"; } ?> </select>; <input type="checkbox" name="qty_matnr" onClick="enable_text(this.checked)" > Qty <input type="text" name="qty_material"> </td> </tr> </table> <INPUT type="button" value="Add Model" onclick="addRow('dataTable')" /> <INPUT type="button" value="Delete Model" onclick="deleteRow('dataTable')" /> </form> </body> </html> I am trying to write a javascript page where the primary form of user input is an HTML form (shown below) Code: <form id=UI> State: <input type="text" name="state" > Postal abriviation: <input type="text" name="ab"> Capital: <input type="text" name="cap"> <input type="button" name="answer" value="Answer" onClick="check()"> <br> <input type="button" name="show_name" value="Show State" onClick="hint=1;select_state();"> <br> <input type="button" name="show_ab" value="Show Abriviation" onClick="hint=2;select_state();"> <br> <input type="button" name="show_cap" value="Show Capitol" onClick="hint=3;select_state();"> </form> the button named 'answer' does what i want, but when the user pushes enter, if he is in one of the form fields it automatically sends him to the url with all of the form date (www.url.com?state=maryland&ab=md&cap=annapolis) i modified my body tag to run the 'check()' function when enter is pushed, which it does but immideatly sends me to the following url Code: <body onload="first_run()" onkeydown="if (event.keyCode == 13){check()}"> is their any way to disable to the submit built into the form tag either through HTML or javascript? Greetings experts, this is my first time here. So, please take easy on me. I have makup with 2 sections. The first section contains 5 form fields and are required. The second second has 2 form fields and are optional. Users can only choose from one section or the other but not both. The js script below ensures that if users select from section 2, section one will not challenge for validation and works a treat. The challenge I have now is to ensure that if users choose from section 1, the 2 form fields in section are automatically disabled so they won't be attempted to choose from it. Similarly, if users select from section 2, all form fields in section one are automatically disabled so they won't be tempted to choose from that section. Is this possible? If not possible, is it possible to raise an error? For instance, a user selects from section 1 and attempts to select from any of the 2 form fields in section 2, a message that says, "You can only select from one section but from both. Similarly if a user selects from section 2 first, same thing happens. Thanks very much for your assistance. function validate() { if(document.getElementById("<%=txtrequest.ClientID%>").value != "" && document.getElementById("<%=txtreceived.ClientID %>").value != "") { if (document.getElementById("<%=txtName.ClientID%>").value == "") { alert("Please enter name"); document.getElementById("<%=txtName.ClientID%>").focus(); return false; } if (document.getElementById("<%=txtCity.ClientID %>").value == "") { alert("Please enter city"); document.getElementById("<%=txtCity.ClientID %>").focus(); return false; } if (document.getElementById("<%=txtState.ClientID%>").value == "") { alert("Please enter state"); document.getElementById("<%=txtState.ClientID%>").focus(); return false; } if (document.getElementById("<%=txtZip.ClientID%>").value == "") { alert("Please enter zip"); document.getElementById("<%=txtZip.ClientID%>").focus(); return false; } if (checkradio() == false) { alert("Please enter contacts"); document.getElementById("<%=txtContacts.ClientID%>").focus(); return false; } } return true; } Hello all, I have 2 radio buttons update bsc value update mnr value when user selects update mnr value, two more radio buttons should appear. I have mnr value I do not have mnr value. On selecing I do not have mnr value im submitting the form and enabling the user to select values from dropdown. ( not shown in the code as it is a coldfusion code.). On submit I am not able to still keep the 'but2', and 'my_select3' elements disabled. Please advice. I have been working on this since quite sometime. <script language="JavaScript"> function makeChoice() { var obj1 = document.getElementById('box1') var obj2 = document.getElementById('box2') if (document.getElementById('but1').checked) { obj2.setAttribute('readOnly','readonly'); obj1.removeAttribute('readOnly'); document.getElementById('but1').disabled=true; document.getElementById('but2').disabled=true; } else if (document.getElementById('but2').checked) { obj1.setAttribute('readOnly','readonly'); obj2.removeAttribute('readOnly'); document.getElementById('but2').disabled=true; document.getElementById('but1').disabled=true; } } </script> <script type="text/javascript"> function showSelect() { if (document.getElementById('but2').checked) { document.getElementById('but2').disabled=true; } } </script> <script type="text/javascript"> function showSelect1() { if (document.getElementById('but2').checked) { document.myform.submit(); document.getElementById('but2').disabled=true document.getElementById('my_select3').disabled=true } } </script> <td><input type="radio" id="but1" name="vals" onclick="makeChoice()"></td> <td>Update BSC Value </td> <tr> <td><input type="radio" id="but2" name="vals" onclick="makeChoice();showSelect();" ></td> <td>Update MNR Value </td> <td> <input id="my_select1" class="show" type="radio" name="my_select1" onclick="this.myform['my_select1'].disabled=true"></td> <td> I have a Position Number </td> <td><input id="my_select3" class="show" type="radio" name="my_select3" onclick="showSelect1();"></td> <td> I do not have a Position Number </td> I found this script, and it works great: Code: <script type="text/javascript"> function disable(element) { var input = document.getElementById(element).getElementsByTagName("input"); for(var i = 0; i < input.length; i++) { input[i].setAttribute("disabled","true"); } } </script> I tried to make the inverse by simply reversing the setAttribute() like so: Code: <script type="text/javascript"> function enable(element) { var input = document.getElementById(element).getElementsByTagName("input"); for(var i = 0; i < input.length; i++) { input[i].setAttribute("disabled","false"); } } </script> But that didn't do it. Can someone show me why, and how to fix it? Here's the sample form which I'm trying to test it on: Code: <form> <input type="radio" name="test" onclick="disable('D1')" /> disable<br/> <input type="radio" name="test" onclick="enable('D1')" /> enable<br/> <fieldset id="D1"> <input class="" type="text" value="test value1" /><input class="" type="text" value="test value2" /><br/> <input class="" type="text" value="test value3" /><input class="" type="text" value="test value4" /><br/> <input class="" type="text" value="test value5" /><input class="" type="text" value="test value6" /><br/> </fieldset> </form> Edit: The ultimate goal which I'm working toward now (step by step =) is to have a form more like: Code: <form> <input type="radio" name="test" onclick="disable('D1')" /> <fieldset id="D1"> <input class="" type="text" value="test value1" /><input class="" type="text" value="test value2" /> </fieldset> <input type="radio" name="test" onclick="disable('D2')" /> <fieldset id="D2"> <input class="" type="text" value="test value3" /><input class="" type="text" value="test value4" /> </fieldset> <input type="radio" name="test" onclick="disable('D3')" /> <fieldset id="D3"> <input class="" type="text" value="test value5" /><input class="" type="text" value="test value6" /> </fieldset> </form> And have the fieldsets enable and disable according the selection of the radio buttons. Also, the fieldsets (and their ID's) will be dynamically generated via PHP Thanks-a-bunch, ~ Mo Hi guys, Been stuck for a few days with this scenario. Any help? The alert box appears on an error. But the submitting won't stop. The details are submitted and the form is processed. Any help is greatly appreciated... Code: <html> <head> <script type="text/javascript" src="email_helper/jscripts/tiny_mce/tiny_mce.js"></script> <script type="text/javascript"> tinyMCE.init({ // General options mode : "textareas", theme : "simple" }); </script> <script language="javascript"> function MM_openBrWindow(theURL,winName,features) { window.open(theURL,winName,features); } function err_check(){ var email = document.getElementById('to_email').value; if(email.length==0){ alert('Please Enter Email Address'); return false; } var AtPos = email.indexOf("@") var StopPos = email.lastIndexOf(".") if (AtPos == -1 || StopPos == -1) { alert("Please Enter Valid Email Address"); document.getElementById('email').focus(); return false; } email = document.getElementById('cc_email').value; if(email.length != 0){ var AtPos = email.indexOf("@") var StopPos = email.lastIndexOf(".") if (AtPos == -1 || StopPos == -1) { alert("Please Enter Valid Email Address"); document.getElementById('email').focus(); return false; } } var answer = confirm ("Send E-Mail?"); if (!answer){ return false; } } </script> <!-- /TinyMCE --> <style type="text/css"> body, table, td, th{ background-color:#CCCCCC; font-family: Arial; font-size:14px; } .que{ font-weight:bold; } </style> </head> <body> <form method="post" enctype="multipart/form-data"> <?php include 'library/database.php'; include 'library/opendb.php'; $query = mysql_query("SELECT email,contact,mobile FROM users WHERE user_id='$uid'") or die(mysql_error()); $row = mysql_fetch_row($query); $from_email = $row[0]; $from_person = $row[1]; $from_mobile = $row[2]; $query = mysql_query("SELECT customer_id FROM campaign_summary WHERE camp_id='$camp_id'") or die(mysql_error()); $row = mysql_fetch_row($query); $cusid = $row[0]; $query = mysql_query("SELECT email FROM client_info WHERE comp_id='$cusid'") or die(mysql_error()); $row = mysql_fetch_row($query); $toer = $row[0]; include 'library/closedb.php'; ?> <table width="100%" border="0"> <tr><td rowspan="4"><input type="submit" name="send_email" id="send_email" style="height:50px; width:100px;" value="SEND" onClick="return err_check();" /></td><td><span class="que">From : </span></td><td colspan="3"><?php echo $from_email; ?><input type="hidden" name="from_mail" id="from_mail" /><input type="hidden" name="camp_id" id="camp_id" value="<?php echo $camp_id;?>"/></td></tr> <tr><td><span class="que">To : </span></td><td colspan="3"><input name="to_email" id="to_email" style="width:250px;" value="<?php echo $toer;?>"/></td></tr> <tr><td><span class="que">CC : </span></td><td colspan="3"><input name="cc_email" id="cc_email" style="width:250px;"/></td></tr> <tr><td><span class="que">Subject : </span></td><td colspan="3"><input style="width:300px;" name="subject" id="subject" /></td></tr> <tr><td rowspan="1" colspan="2"> </td><td><input type="checkbox" name="ori_pdf" id="ori_pdf" checked /> PDF Quotation</td><td> </td><td> </td></tr><tr><td colspan="2"><span class="que">Credit Application</span></td><td><input type="checkbox" name="corporate" id="corporate"/>Corporate</td><td><input type="checkbox" name="individual" id="individual" />Individual</td><td><input type="checkbox" name="cash" id="cash" />Cash Account</td> </tr> <tr> <td colspan="2" rowspan="3"></td><td><input type="checkbox" name="tabloid" id="tabloid" />Tabloid Example</td> <td><input type="checkbox" name="broadsheet" id="broadsheet" />Broadsheet Example</td></tr> <tr><td><input type="checkbox" name="colmt" id="colmt" />Column Sizes Tabloid</td> <td><input type="checkbox" name="colmb" id="colmb" />Column Sizes Broadsheet</td></tr> <tr><td><input type="checkbox" name="maps" id="maps" />Maps / Distribution</td><td colspan="2" align="right">External Attachments <input id="upload_file" name="upload_file" type="file"/> </td></tr> <tr><td colspan="2"><span class="que">Message :</span></td><td colspan="3"> <textarea id="elm1" name="elm1" rows="15" cols="80" style="width: 100%"> <?php echo "<br><br><br>" . $from_person . "<br>" . $from_mobile; ?> </textarea> </td></tr> </table> </form> </body> </html> Hi all, I have created a contact form using php and have added some javascipt code to validate the fields, problem is the validation isnt working. Can anyone give me a little advice on how i can get this working? Page is located he http://www.brownscountryhouse.co.uk/testing/test.php The javascript used is: Code: <script language="javaScript"> function ValidateForm(){ var numeID=document.form1.nume var surnameID=document.form1.surname var emailID=document.form1.email if ((numeID.value==null)||(numeID.value=="")){ alert("Please enter your name") numeID.focus() return false } if ((surnameID.value==null)||(surnameID.value=="")){ alert("Please enter your surname") surnameID.focus() return false } if ((emailID.value==null)||(emailID.value=="")){ alert("Please enter your email address") emailID.focus() return false } if (echeck(emailID.value)==false){ emailID.value="" emailID.focus() return false } return true } function echeck2(str) { alert("Invalid E-mail Address") return false } function echeck(str) { var at="@" var dot="." var lat=str.indexOf(at) var lstr=str.length var ldot=str.indexOf(dot) if (str.indexOf(at)==-1){ alert("Invalid Email Address") return false } if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){ alert("Invalid Email Address") return false } if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){ alert("Invalid Email Address") return false } if (str.indexOf(at,(lat+1))!=-1){ alert("Invalid Email Address") return false } if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){ alert("Invalid Email Address") return false } if (str.indexOf(dot,(lat+2))==-1){ alert("Invalid Email Address") return false } if (str.indexOf(" ")!=-1){ alert("Invalid Email Address") return false } return true } </script> Thanks in advance for looking! Kyle Hi all, ive been staring at this code for over an hour now and i cant see what is wrong with it. any chance of a wee look over for me ? Thank you Code: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML><HEAD><TITLE>Comment Form</TITLE> <META http-equiv=Content-Type content="text/html; charset=windows-1252"> <SCRIPT language=javascript> function Validate() { var Message = "" Message = Message + Checkname() if (Message == ""){ return true } else { alert(Message) return false } } function CheckName() { var UserName = document.form.name.value if (UserName == "") { Message = "Something's wrong with your forename" + "\n" } else { Message = "" } return Message } </SCRIPT> </HEAD> <BODY> <FORM name=form onsubmit="return Validate()" action="sent.htm" method=post encType=text/plain> <TABLE BORDER=1 CELLSPACING=0> <TBODY> <TD> <TABLE BORDER=0 CELLSPACING=5> <TR> <TD><font size="2" face="Verdana"><b>Forename:</b></TD> <TD><INPUT NAME=name size=25></TD> </TR> <TR> <TD></TD> <TD align=right> <INPUT TYPE=reset VALUE="Reset" name=submit2> <INPUT TYPE=submit VALUE="Submit" NAME=Submit> </TD> </TR> </TBODY> </TABLE> </TABLE> </FORM> </BODY> </HTML> Hi I am new to teaching JavaScript I need to show how to create a form with validation and feedback. I can get it to validate a text with a message, but I cannot get it to validate a set of radio buttons and conform the radio selected. Code below- <html> <head> <title>Exam entry</title> <script language="javascript" type="text/javascript"> function validateForm() { var result = true; var msg=""; if (document.ExamEntry.name.value=="") { msg+="You must enter your name \n"; document.ExamEntry.name.focus(); document.getElementById('name').style.color="red"; result = false; if (document.ExamEntry.subject.value=="") { msg+="You must enter the subject \n"; document.ExamEntry.subject.focus(); document.getElementById('subject').style.color="red"; result = false; } } if(msg==""){ return result; } { alert(msg) return result; } } </script> </head> <body> <h1>Exam Entry Form</h1> <form name="ExamEntry" method="post" action="success.html"> <table width="50%" border="0"> <tr> <td id="name">Name</td> <td><input type="text" name="name" /></td> </tr> <tr> <td id="subject">Subject</td> <td><input type="text" name="subject" /></td> </tr> <tr> <td><input type="reset" name="Reset" value="Reset" /></td> </tr> </table> </form> <script type="text/javascript"> function lengthpass() { var s1=document.getElementById("password"); if(s1.value.length != 4) { alert("Please enter an exam number which is 4 characters long"); return false; } return true; } </script> </head> <body> <form onsubmit="return lengthpass();"> Exam Code <input type="text" id="password" name="password"> (Four Numbers) <br> <br> <h1>option button form validation</h1> <script type="text/javascript"> function option1() { var checkedop=null; var examop=document.getElementsByName("exam"); for (var i = 0;i<examop.length;i++) { if(examop[i].checked) { checkedop=examop[i]; } } if(checkedop==null) { alert("please select an exam"); return false; } { confirm("you have chosen"+checkedop.value+ "is this correct?"); } } </script> </head> <body> <form name="examtype" onsubmit="return option1();"> Select an exam type<br> <input type="radio" name = "exam"value= "GCSE"> GCSE<br> <input type="radio" name = "exam"value= "AS"> AS<br> <input type="radio" name = "exam"value= "A2"> A2<br> <input type="submit"name="submit"value="Submit Form"/> </form> </body> </html> I have a button that works fine in every browser EXCEPT IE8, and I can't seem to figure out why, I would assume its a Jvascript issue, here's the code, any help would be great thanks guys... THE button that doesn't work in IE is the one with the value "Proceed to your order" at the bottom, the other two, delete and recalculate work fine.??? Code: <form action="/cart" method="post" id="form"> <table width="100%" cellspacing="0" cellpadding="0" style="margin-top:30px"> <thead class="tableTitle"><tr> <td width="20"><!--<input type="checkbox" value="" checked="" onclick="checkAll(this)" />--></td> <td>Title</td> <td>Quantity</td> <td>Price</td> </tr></thead><tbody class="tableBody"> <?foreach ($goods as $k => $v){$randId = randId();?> <tr> <td><input type="checkbox" name="deleteCheckbox[]" class="checkboxes" value="<?=$v['id']?>" /></td> <td width="400"><strong><?=$v['title']?></strong><br /> Color: <select onchange="updateExtras('color', <?=$k?>, this.value)" class="checkMe"> <option value="0">Specify color</option> <?if (count($v['colors'])) foreach ($v['colors'] as $colorK => $colorV){?> <option value="<?=$colorV['id']?>" <?if ($colorV['id'] == $v['colorId']){?>selected="selected"<?}?>><?=$colorV['item']?></option> <?}?> </select> Size:<select onchange="updateExtras('size', <?=$k?>, this.value)" class="checkMe"> <option value="0">Specify size</option> <?if (count($v['sizes'])) foreach ($v['sizes'] as $colorK => $colorV){?> <option value="<?=$colorV['id']?>" <?if ($colorV['id'] == $v['sizeId']){?>selected="selected"<?}?>><?=$colorV['item']?></option> <?}?> </select> <?if ($_SESSION['cartDetails'][$v['id']]['size']){?> <div style="font-size:0.9em; margin-top:5px"><strong>Size</strong>: <?=$_SESSION['cartDetails'][$v['id']]['size']?></div> <?}?> <?if ($_SESSION['cartDetails'][$v['id']]['color']){?> <strong>Color</strong>: <?=$_SESSION['cartDetails'][$v['id']]['color']?><?}?> </td> <td width="100"><input type="text" value="<?=$v['q']?>" size="5" name="ammounts[]" /></td> <td>$<span id="<?=$randId?>"><?=$v['totalPrice']?></span> CAD<br /><span style="color:#ccc">($<?=$v['price']?> per each)</span></td> </tr> <?}?> <tr class="totalPrice"> <td></td> <td width="400" style="font-size:1em; font-style:italic">Total price</td> <td width="100"></td> <td style="font-size:1em; font-style:italic">$<span id="totalPriceHere"><?=$totalPrice?></span> CAD</td> </tr> </tbody> <tfoot class="tableFoot"><tr><td colspan="4"></td></tr></tfoot> </table> <div style="margin-top:10px;"> <input type="submit" value="Delete selected" id="deleteButton" class="button left" /> <a href="/cart/proceed" onclick=" var stop = false; $('.checkMe').each(function(){ if ($(this).attr('value') == 0) {stop = true} return }) if (stop) { $('#alert').html('Choose colors and sizes for each item to proceed!'); return false } return true "><input type="button" value="Proceed to your order" class="button right" /></a> <a href="#" onclick="$('#form').attr('action', '/cart/recalc'); $('#form').submit()"><input type="button" value="Recalculate" style="margin-right:10px" class="button right" /></a> I'm a newbie to scripting who needs help. The situation is as follows: I'm running Joomla 1.5.23 and I've been trying to get validation on a component's form fields. In the header section, I'm properly loading the validator.js file, which contains the following: Code: //function to check empty fields function isEmpty(strfield1, strfield2) { strfield1 = document.forms[0].firstname.value strfield2 = document.forms[0].lastname.value //firstname field if (strfield1 == "" || strfield1 == null || !isNaN(strfield1) || strfield1.charAt(0) == ' ') { alert("\"firstname\" is a mandatory field.\nPlease amend and retry.") return false; } //lastname field if (strfield2 == "" || strfield2 == null || strfield2.charAt(0) == ' ') { alert("\"lastname" is a mandatory field.\nPlease amend and retry.") return false; } } return true; } //function to check valid email address function isValidEmail(strEmail){ validRegExp = /^[^@]+@[^@]+.[a-z]{2,}$/i; strEmail = document.forms[0].email.value; // search email text for regular exp matches if (strEmail.search(validRegExp) == -1) { alert('A valid e-mail address is required.\nPlease amend and retry'); return false; } return true; } //function that performs all functions, defined in the onsubmit event handler function check(form)){ if (isEmpty(form.firstname)){ if (isEmpty(form.lastname)){ if (isValidEmail(form.email)){ return true; } } } return false; } I'm invoking this in this way: Code: <form action="index.php?option=com_pbbooking&task=save" method="POST" onsubmit="return check(this);"> My problem is that even if all fields are empty it will go to the next step. Thanks in advance, twdk01. Hey All, I have the following function - where I can get one of the conditions to work, but not both together. Here's the code: Code: function test_function() { $('#form_field_name').focus(); window.location = window.location + "#form_field_name"; } Basically when clicking an error link, I want to focus onto the form field, and then move to the anchor itself on the page. One of these will work at a time, but not both and I'm not sure why. Any suggestions would be appreciated. Thanks. Hi, Posting this in javascript because the problem might be caused by my scripting. I made a 3 page long form using javascript, and the contents of the second page aren't submitted to the php script. link Hope someone can check it for errors. Thanks! I have a simple form here with a function to validate it, but I have no idea where I'm going wrong. I'm very familiar with ActionScript and C++, so I get the coding aspect of it, but one thing I'm not familiar with is how exactly JavaScript and HTML communicate. The problem is that this form always submits, even if my function returns false...but I can't even see if it returns false anyway, because alert() doesn't seem to be working either. Here's what I have for my HTML: Code: <form name="myForm" onSubmit="return checkForm();" action="processForm.php" method="post"> <input type="text" size="25" name="firstName" value="*First Name" /> <br /> <input type="text" size="25" name="lastName" value="Last Name" /> <br /> <input type="text" size="25" name="phoneNumber" value="Phone" /> <br /> <input type="text" size="25" name="emailAddress" value="*Email" /> <br /> <textarea rows="6" cols="20">Message</textarea> <input type="submit" value="Submit" /> </form> And here's the JavaScript function: Code: function checkForm(){ with(firstName){ if(value==NULL || value=="" || value==defaultValue){ return false;} } with(emailAddress){ if(value==NULL || value=="" || value==defaultValue){ return false;} } return true; } What bugs me is even when I try to check my work by using alert statements to see what parts of the code are being executed, they never seem to come up. So it's kind of left me doing lots of guessing and trying a million things. Even if that last line in the JS function is "return false," the form still submits anyway. What am I doing wrong and how can I fix this up? This is straight out of an O'Riley book, everything looks good to me but for some reason the script does nothing when I try to submit an empty form. Code: // Validate Registration Form function validate(form) { fail = validateUsername (form.uname.value) fail += validateUpass (form.upass.value) fail += validatePassword (form.password.value) fail += validateFname (form.fname.value) fail += validateLname (form.lname.value) fail += validateID (form.ID.value) fail += validateEmail (form.email.value) if (fail =="") return true else {alert(fail); return false } } function validateUsername (field) { if (value==null||value=="") return "Please enter username.\n" return "" } function validateUpass (field) { if (field =="") return "Please enter password.\n" return "" } function validatePassword (field) { if (value == "") return "Please confirm password. \n" return "" } function validateFname (field) { if (value =="") return "Please enter a first name.\n" return"" } function validateLname (field) { if (value=="") return "Please enter a last name.\n" return"" } function validateID (field) { if (value=="") return "Please enter your USAC license number.\n" return "" } function validateEmail (field) { if (value=="") return "Please enter your email address.\n" else if (!((field.indexof(".")>0) && (field.indexOf("@") > 0)) || /[^a-zA-Z0-9.@_-]/.test(field)) return "The Email address is invalid.\n" return"" } Code: <script src="includes/js/validate-registration-form.js"></script> </head> <body> <div id="wrap"> <h1>CritTracker.com Registration page</h1> <?php include('includes/nav.php');?> <div id="content_wrap"> <div id="center_content"> <div id="register"> <form class="register" method="post" action="register.php" onSubmit="return validate(this)"> <fieldset> <legend>Register to CritTracker</legend> <ol> <li> <label for="uname">Username</label> <input type="text" name="uname" /><br /> </li> <li> <label for="upass">Password</label> <input type="password" name="upass" /><br /> </li> <li> <label for="upass">Confirm Password</label> <input type="password" /><br /> </li> <li> <label for="fname">First Name</label> <input type="text" name="fname" /><br /> </li> <li> <label for="lname">Last Name</label> <input type="text" name="lname" /><br /> </li> <li> <label for="ID">USA Cycling License</label> <input type="text" name="ID" /> <select name="cat"> <option name="cat" value="5">Cat 5</option> <option name="cat" value="4">Cat 4</option> <option name="cat" value="3">Cat 3</option> <option name="cat" value="2">Cat 2</option> <option name="cat" value="1">Cat 1</option> </select> </li> <li> <label for="email">Email</label> <input type="text" name="email" /><br /> <input type="submit" value="Register to CritTracker.com" /> </li> </ol> </fieldset> </form> </div></div> Hello: I am using javascript validation for submitting a form. All the other fields are working except for the Terms of Use checkbox. It sends and alert and says it wasn't checked whether or not you check it. It also submits the form whether or not it is checked immediately after the alert. The field is called df_Terms. Can anyone see anything I am missing? Code: <script> //submit after validation functionality function submit_onclick() { var proceed = false; if (typeof validateForm == "function") { proceed = validateForm(); } else { proceed = true; } return proceed; } //validation functionality function validateForm() { if ((document.form1.df_Plans[0].checked == false) && (document.form1.df_Plans[1].checked == false)) { alert("Please select Your Plan"); document.form1.df_Plans[0].focus(); return false; } if ("" == document.form1.df_first_Name1.value) { alert("Please enter your First Name"); document.form1.df_first_Name1.focus(); return false; } if ("" == document.form1.df_last_Name1.value) { alert("Please enter your Last Name."); document.form1.df_last_Name1.focus(); return false; } if ("" == document.form1.df_email1.value) { alert("Please enter your email."); document.form1.df_email1.focus(); return false; } validRegExp = /^[^@]+@[^@]+.[a-z]{2,}$/i; strEmail = document.form1.df_email1.value; if (strEmail.search(validRegExp) == -1) { alert("A valid e-mail address is required."); document.form1.df_email1.focus(); return false; } if (!document.form1.df_Terms.checked == 1) { alert("Please agree to the Terms of Use."); document.form1.df_Terms.focus(); return false; } } //reset field functionality function reset_onclick() { for (i = 0; i < document.form1.elements.length; i++) { if (document.form1.elements[i].type == "text") { document.form1.elements[i].value = ""; } if (document.form1.elements[i].type == "checkbox") { document.form1.elements[i].checked = false; } if (document.form1.elements[i].type == "radio") { document.form1.elements[i].checked = false; } if (document.form1.elements[i].type == "select-one") { document.form1.elements[i].selectedIndex = 0; } } } //redirect functionality function redirect_onclick(urlString) { window.open("http://" + urlString); } </script> Hello JScript gurus, though I am quite an advanced and experienced VB& .NET programmer, I am totally new to Jscript coding, (I don't actually code Jscript) but I build websites all the same too. I am also new here. I really need help from you gurus here. I am working on a website and I really wish to incorporate a contact or an order form to it so that when the user fills in the fields and clicks send, I receive the data in my email. I have made some searches and found quite a few but all didn't touch on how I retrieve my data. Please help me. I will be very grateful. Thank you. Hi, Please this form code is not working,please help correct me with the right code. When i did not enter anything onthe field require ,thealert does not pop up making the form inaccurate. Code: <script type="text/javascript"> function validateForm() { function CheckEmail() var x=document.frmone.email.value; var atpos=x.indexOf("@"); var dotpos=x.lastIndexOf("."); if(atpos<1 || dotpos<atpos+2 ||x.length>30){ alert("not a valide email address"); return false } function CheckUsername() { var x=document.frmone.fname.value; if(x==null || x==""){ alert("username is required"); return false } } </script> <form name="frmone" method="post" action="" onsubmit="validateForm()"/> <input type="text" name="email"/> <input type="submit" name="submit"/> <input type="text" name="fname"/> <input type="submit" name="submit"/> </form> Help me. Thanks. Clement Osei. Hi there! I hope someone can help me figure out the last little bit of this project. I'm building a form that is calulated based on the options selected with a javascript form. This is my first attempt at something like this so I'm a bit lost at the final update. First to be sure I'm on spot here is the javascript I'm using to update the form - Code: <script> function BDWcalc () { var listeners = document.getElementById('listeners').value; var bitrate = document.getElementById('bitrate').value; var hours = document.getElementById('hours').value; var days = document.getElementById('days').value; var total = document.getElementById('BDWTotal'); var sum = days*hours*3600*bitrate/8*listeners/1024/1024; total.value = sum.toFixed(2)+" GB"; } </script> I'm calling the script in the header of the site with the following line of code Code: <script type="text/javascript" language="JavaScript" src='javascript/BDWcalc.js'></script> Now here is the form where I get stuck. It the last field which is to be updated when the option values are changed. For my purposes here, I've merely created a correct value as a default based on the items selected, but it is not actually being calculated by the script. I need the correct syntax there to get this all to work. Sure hope someone can help - Form Code: <table width="530" border="0" cellspacing="0" cellpadding="5"> <tr> <th scope="col">Listeners</th> <th scope="col">Bitrate(quality)</th> <th scope="col">Hours per day </th> <th scope="col">Days per month </th> <th scope="col">Total per month </th> <th scope="col">Action</th> </tr> <tr> <th scope="col"><span class="cell" style="width: 75px;"> <input name="text" type="text" id="listeners" style="margin: 4px 2px 0pt; width: 65px;" onchange="BDWcalc();" value="10" size="20" /> </span></th> <th scope="col"><span class="cell_v"> <select name="select2" class="BDWbox" id="select" onchange="BDWcalc();"> <option value="24">24 kbps</option> <option value="32">32 kbps</option> <option value="48">48 kbps</option> <option value="56">56 kbps</option> <option value="64" selected="selected">64 kbps</option> <option value="80">80 kbps</option> <option value="96">96 kbps</option> <option value="112">112 kbps</option> <option value="128">128 kbps</option> <option value="160">160 kbps</option> <option value="192">192 kbps</option> <option value="224">224 kbps</option> <option value="256">256 kbps</option> <option value="320">320 kbps</option> <option value="512">512 kbps</option> <option value="768">768 kbps</option> <option value="1536">1.5 mbps</option> </select> </span></th> <th scope="col"><span class="cell_v"> <select name="select3" class="BDWbox" id="select2" onchange="BDWcalc();"> <option value="1">1 hour</option> <option value="2">2 hours</option> <option value="3">3 hours</option> <option value="4">4 hours</option> <option value="5">5 hours</option> <option value="6">6 hours</option> <option value="7">7 hours</option> <option value="8">8 hours</option> <option value="9">9 hours</option> <option value="10" selected="selected">10 hours</option> <option value="11">11 hours</option> <option value="12">12 hours</option> <option value="13">13 hours</option> <option value="14">14 hours</option> <option value="15">15 hours</option> <option value="16">16 hours</option> <option value="17">17 hours</option> <option value="18">18 hours</option> <option value="19">19 hours</option> <option value="20">20 hours</option> <option value="21">21 hours</option> <option value="22">22 hours</option> <option value="23">23 hours</option> <option value="24">24 hours</option> </select> </span></th> <th scope="col"><span class="cell_v"> <select name="select4" class="BDWbox" id="select3" onchange="BDWcalc();"> <option value="1">1 day</option> <option value="2">2 days</option> <option value="3">3 days</option> <option value="4">4 days</option> <option value="5">5 days</option> <option value="6">6 days</option> <option value="7">7 days</option> <option value="8">8 days</option> <option value="9">9 days</option> <option value="10">10 days</option> <option value="11">11 days</option> <option value="12">12 days</option> <option value="13">13 days</option> <option value="14">14 days</option> <option value="15" selected="selected">15 days</option> <option value="16">16 days</option> <option value="17">17 days</option> <option value="18">18 days</option> <option value="19">19 days</option> <option value="20">20 days</option> <option value="21">21 days</option> <option value="22">22 days</option> <option value="23">23 days</option> <option value="24">24 days</option> <option value="25">25 days</option> <option value="26">26 days</option> <option value="27">27 days</option> <option value="28">28 days</option> <option value="29">29 days</option> <option value="30">30 days</option> </select> </span></th> <th scope="col"><span class="cell_v" style="width: 160px;"> <input name="text2" type="text" id="text2" style="margin: 4px 2px 0pt; width: 90px;" value="41.19 GB" size="20" /> </span></th> <th scope="col"><a href='javascript:BDWcalc();'>Update</a></th> </tr> </table> The form can be view here Thank you in advance for any help offered. I've search and found things that are similiar, but none that are exactly what I need here. Ruth |