JavaScript - Javascript Form Validation When Submit Button Is Pressed?
Hello all
I created a form which has a lot of textboxes, checkboxes and select-lists which are getting filled up by the records from a database table. I am basically creating an edit screen for a record. No I want to check all these input elements using javascript validation. I want this to performed when a button "Archive" is pressed. My problem is this "Archive button" needs to be a submit button. This does run the javascript validation but after completing the validation it submits the form. I want that submission should be stopped when the validation is violated. how can I do this? What I want is a button which acts as a default button (triggers the onclick event when I press enter) but submits only if the form is valid. Similar TutorialsIs there a way to stop a form submit after hitting submit? Refresh wouldn't realy be an option. Is abort() what I'm looking for?
I have a simple form and am validating onchange and need a final validation onsubmit. I am displaying a message to the right of the inputbox on error. I'm trying to keep this at DOM 1 compatible and not use any framework. HTML Code: <form id = "myForm" action = "" onsubmit = "return validateForm(this);"> <table class = "table-submit" border = "0"> <tr> <td> Username: </td> <td> <input type = "text" id = "username" size = "30" maxlength = "30" onchange = "validateUsername(this, 'msgUsername')" /> </td> <td id = "msgUsername"> </td> </tr> <tr> <td> Password: </td> <td> <input type = "password" id = "password" size = "30" maxlength = "30" onchange = "validatePassword(this, 'msgPassword')" /> </td> <td id = "msgPassword"> </td> </tr> <tr> <td> </td> <td> <input type = "submit" value = "Submit" /> <input type = "reset" value = "Clear" /> </td> </tr> </table> </form> JavaScript Code: function validateUsername(myItem, myElement) { var dom = document.getElementById(myElement); if (myItem.value.length < 3) { dom.innerHTML = " Username needs to be a minimum of 3 characters! "; return false; } else { dom.innerHTML = ""; return true; } } function validatePassword(myItem, myElement) { var dom = document.getElementById(myElement); if (myItem.value.length < 5) { dom.innerHTML = " Password needs to be a minimum of 5 characters! "; return false; } else { dom.innerHTML = ""; return true; } } function validateForm (itm) { // kind of stuck here... } As you may of noticed, I am a bit stuck on my validateForm() function. The code validates on each inputbox onchange event. Not sure what is the best way to go from here. I thought about doing an If for my both single input box validation, but I would need to send each parameters which is what i was trying to avoid by using this. Would like some suggestions. I've literally tried everything. Read 26 tutorials, interchanged code, etc. My validation functions all work. My AJAX functions work (tested manually using servlet URL's). The second servlet validates the reCaptcha form that's generated on my webpage. After the form is validated, even if everything's correct, nothing happens upon clicking submit. I even have an alert pop up if with the captcha result, just for middle-layer debugging purposes. I want to do all of my validation clientside; none serverside. However, going to be tough if I can't get my god damn form to submit. I've been puzzled by this for close to 36 hours straight. I can't see, and I'm going to get some rest and hope that there is some useful insight on my problem when I return. html form: Code: <form id="f1" name="form1" onsubmit="validate_form(this); return false;" action="register" method="post"> <table cellspacing="5" style="border: 2px solid black;"> <tr> <td valign="top"> <table cellspacing="5"> <tr> <td>*First name</td> <td align="right"><span id="valid_one"></span></td> <td><input type="text" style="width: 320px;" id="fn" name="fn" onBlur="validate_one();"></td> </tr> <tr> <td align="left">*Last name</td> <td align="right"><span id="valid_two"></span></td> <td><input type="text" style="width: 320px;" id="ln" name="ln" onBlur="validate_two();"></td> </tr> <tr> <td align="left">*Email address</td> <td align="right"><span id="result"></span></td> <td><input type="text" style="width: 320px;" id="mailfield" name="email" onBlur="startRequest();"></td> </tr> <tr> <td align="left">*Phone number</td> <td align="right"><span id="valid_three"></span></td> <td><input type="text" style="width: 320px;" id="pn" name="pn" onBlur="validate_three();"></td> </tr> <tr> <td align="left">*City/Town</td> <td align="right"><span id="valid_four"></span></td> <td><input type="text" style="width: 320px;" id="c" name="c" onBlur="validate_four();"></td> </tr> <tr> <td></td> <td></td> <td> <select name="s"> <option value="AL">Alabama <option value="AK">Alaska <option value="AZ">Arizona <option value="AR">Arkansas <option value="CA">California <option value="CO">Colorado <option value="CT">Connecticut <option value="DE">Delaware <option value="FL">Florida <option value="GA">Georgia <option value="HI">Hawaii <option value="ID">Idaho <option value="IL">Illinois <option value="IN">Indiana <option value="IA">Iowa <option value="KS">Kansas <option value="KY">Kentucky <option value="LA">Louisiana <option value="ME">Maine <option value="MD">Maryland <option value="MA">Massachusetts <option value="MI">Michigan <option value="MN">Minnesota <option value="MS">Mississippi <option value="MO">Missouri <option value="MT">Montana <option value="NE">Nebraska <option value="NV">Nevada <option value="NH">New Hampshire <option value="NJ">New Jersey <option value="NM">New Mexico <option value="NY">New York <option value="MC">North Carolina <option value="ND">North Dakota <option value="OH">Ohio <option value="OK">Oklahoma <option value="OR">Oregon <option value="PA">Pennsylvania <option value="RI">Rhode Island <option value="SC">South Carolina <option value="SD">South Dakota <option value="TN">Tennessee <option value="TX">Texas <option value="UT">Utah <option value="VT">Vermont <option value="VA">Virginia <option value="WA">Washington <option value="WV">West Virginia <option value="WI">Wisconsin <option value="WY">Wyoming </select> </td> </tr> <tr> <td> <br> </td> </tr> <tr> <td></td> <td></td> <td><span id="error"></span></td> </tr> <tr> <td valign="top">*Anti-Spam Verification</td> <td></td> <td id="reCaptcha"></td> </tr> </table> </td> <td valign="top"> <table cellspacing="5"> <tr> <td align="left">*Affiliation</td> <td align="right"><span id="valid_five"></span></td> <td><input type="text" style="width: 320px;" id="affl" name="affl" onBlur="validate_five();"></td> </tr> <tr> <td align="left">*Research Area:</td> <td align="right"><span id="valid_six"></span></td> <td><input type="text" style="width: 320px;" id="ra" name="ra" onBlur="validate_six();"></td> </tr> <tr> <td valign="top" align="left">*Research Overview</td> <td align="right"><span id="valid_seven"></span></td> <td><textarea cols="38" rows="6" id="ro" name="ro" onKeyDown="limitText(this.form.ro,this.form.countdown,500)" onKeyUp="limitText(this.form.ro,this.form.countdown,500)" onBlur="validate_seven();"></textarea></td> </tr> <tr> <td></td> <td></td> <td><font size="1">You have <input readonly type="text" name="countdown" size="1" value="500"> characters remaining.</font></td> </tr> <tr> <td align="left">*Talk Availability</td> <td></td> <td> <input type="radio" name="ta" value="In person">In person <input type="radio" name="ta" value="Online">Online <input type="radio" name="ta" value="Both" checked>Both </td> </tr> <tr> <td align="left" valign="top">Links</td> <td></td> <td> <table id="linkTable" border="0"> <td><input type="text" style="width: 320px;" name="link"></td> <td><div id="result"></div></td> </table> </td> <td align="left" valign="top"><input type="button" value="Add Link" onclick="addLink('linkTable')"></td> </tr> <tr> <td></td> <td><span style="color: red;"></span></td> </tr> </table> </td> </tr> </table> <br /> <input type="submit" id="submit" name="submit" value="Submit Form"> </form> Javascript file: Code: /* * script.js - ajax and table functions */ var xmlHttp; // global instance of XMLHttpRequest var xmlHttp2; // second for captcha functions var validAjax = new Boolean(); var validCaptcha = new Boolean(); var valid_one = new Boolean(); var valid_two = new Boolean(); var valid_three = new Boolean(); var valid_four = new Boolean(); var valid_five = new Boolean(); var valid_six = new Boolean(); var valid_seven = new Boolean(); function init() { showRecaptcha('reCaptcha'); // Separate booleans for AJAX funcs validAjax = false; validCaptcha = false; // Booleanse for fields that don't require servlet validation valid_one = false; valid_two = false; valid_three = false; valid_four = false; valid_five = false; valid_six = false; valid_seven = false; } function showRecaptcha(element) { Recaptcha.create("6Le1a8ESAAAAAGtxX0miZ2bMg0Wymltnth7IG-Mj", element, {theme: "red", callback: Recaptcha.focus_response_field}); } function validate_form() { if (valid_one && valid_two && valid_three && valid_four && validEmail) { startCaptchaRequest(); if (validCaptcha) { return true; } } else { alert("Submission contains errors. Please fill out all required fields before submitting."); return false; } } function validate_one() { if (document.getElementById("fn").value == 0) { valid_one = false; document.getElementById("valid_one").innerHTML = "No"; } else { valid_one = true; document.getElementById("valid_one").innerHTML = ""; } } function validate_two() { if (document.getElementById("ln").value == 0) { valid_two = false; document.getElementById("valid_two").innerHTML = "No"; } else { valid_two = true; document.getElementById("valid_two").innerHTML = ""; } } function validate_three() { if (document.getElementById("pn").value == 0) { valid_three = false; document.getElementById("valid_three").innerHTML = "No"; } else { valid_three = true; document.getElementById("valid_three").innerHTML = ""; } } function validate_four() { if (document.getElementById("c").value == 0) { valid_four = false; document.getElementById("valid_four").innerHTML = "No"; } else { valid_four = true; document.getElementById("valid_four").innerHTML = ""; } } function validate_five() { if (document.getElementById("affl").value == 0) { valid_five = false; document.getElementById("valid_five").innerHTML = "No"; } else { valid_five = true; document.getElementById("valid_five").innerHTML = ""; } } // //function validate_six() { // if (document.getElementById("ra").value == 0) { // valid_six = false; // document.getElementById("valid_six").innerHTML = "No"; // } // else { // valid_six = true; // document.getElementById("valid_six").innerHTML = ""; // } //} // //function validate_seven() { // if (document.getElementById("ro").value == 0) { // valid_seven = false; // document.getElementById("valid_seven").innerHTML = "No"; // } // else { // valid_seven = true; // document.getElementById("valid_seven").innerHTML = ""; // } //} function addLink(tableID) { var table = document.getElementById(tableID); var rowCount = table.rows.length; var row = table.insertRow(rowCount); var cell = row.insertCell(0); var element1 = document.createElement("input"); element1.type = "text"; element1.name = "link" + rowCount; element1.style.width = "320px"; cell.appendChild(element1); } function limitText(limitField, limitCount, limitNum) { if (limitField.value.length > limitNum) { limitField.value = limitField.value.substring(0, limitNum); } else { limitCount.value = limitNum - limitField.value.length; } } function createXmlHttpRequest() { if(window.ActiveXObject) { xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); } else if(window.XMLHttpRequest) { xmlHttp=new XMLHttpRequest(); } } function startRequest() { createXmlHttpRequest(); var param1 = document.getElementById('mailfield').value; if (param1 == "") { validEmail = false; document.getElementById("result").innerHTML = "Blank"; } else { xmlHttp.open("GET", "http://localhost:1979/PolarSpeakers/servlet/mailCheck.do?e=" + param1, true) xmlHttp.onreadystatechange = handleStateChange; xmlHttp.send(null); } } function handleStateChange() { if(xmlHttp.readyState==4) { if(xmlHttp.status==200) { var message = xmlHttp.responseXML .getElementsByTagName("valid")[0] .childNodes[0].nodeValue; if (message == "Unregistered") { validEmail = true; document.getElementById("result").style.color = "green"; } else { validEmail = false; document.getElementById("result").style.color = "red"; } document.getElementById("result").innerHTML = message; } else { alert("Error checking e-mail address - " + xmlHttp.status + " : " + xmlHttp.statusText); } } } function createCaptchaRequest() { if(window.ActiveXObject) { xmlHttp2=new ActiveXObject("Microsoft.XMLHTTP"); } else if(window.XMLHttpRequest) { xmlHttp2=new XMLHttpRequest(); } } function startCaptchaRequest() { alert('made it to captcha requeswt'); createCaptchaRequest(); var param1 = Recaptcha.get_challenge(); var param2 = Recaptcha.get_response(); xmlHttp2.open("POST", "http://localhost:1979/PolarSpeakers/servlet/captchaCheck.do?c=" + param1 + "&r=" + param2, true) xmlHttp2.onreadystatechange = handleStateChangeCaptcha; xmlHttp2.send(null); } function handleStateChangeCaptcha() { if(xmlHttp2.readyState==4) { if(xmlHttp2.status==200) { var message = xmlHttp2.responseXML .getElementsByTagName("result")[0] .childNodes[0].nodeValue; if (message == "Valid") { alert("captcha valid"); validCaptcha = true; } else { document.getElementById("error").innerHTML = message; validCaptcha = false; } } else { alert("Error checking captcha validity - " + xmlHttp2.status + " : " + xmlHttp2.statusText); } } } Hi everyone, I currently use javascript in an anchor tag to submit a form using Code: <a href="#" onClick="document.myformname.submit(); return false;">Submit</a> The only problem is, JQuery doesn't acknowledge that my form has been submitted. Has anyone come up against this problem before? If so, can you please share your work around? Thank you! B Hi, I am having a problem with my script used to disable my submit button. I want the button to disable upon correct submission of the form, and the button to be kept enabled if the required fields are not filled in. I have the following code at the moment (which only does the first if statement). Code: SCRIPT CODE: <script type="text/javascript" > function validateForm() { var amount=document.forms["expenserecord"]["amount"].value; var picker=document.forms["expenserecord"]["picker"].value; var desc=document.forms["expenserecord"]["description"].value; if (amount==null || amount=="" || picker==null || picker=="" || desc==null || desc=="") { alert("All required fields must be filled out."); document.getElementById("sub").disabled = false; return false; } else { document.getElementByID("sub").disabled = true; } } </script> BUTTON CODE: <p><input type="submit" value="Submit" onClick="return validateForm()" id="sub"></p> how do i make a html button stay down when pressed, until another button within a specified group of buttons is pressed, at which point it is released and the other button stays pressed?
Hi guys, would appreciate some help here. The below is part of the codes of my image matching programme. The programme loads 2 different series of images in the area and the up/down button is supposed to change each set of the series of images. Currently, the codes only allow one set of the images to be changed. Any idea what can be done so that both set get changes when the up/down key is pressed? Thanks! Codes: public void keyReleased(KeyEvent e) { zoom = false; repaint(); } public void keyPressed(KeyEvent e) { System.out.println("" + e.getKeyCode()); switch (e.getKeyCode()) { case 16: zoom = true; zoomPt = getMousePosition(); repaint(); break; case 39: loadImage(true, true); break; case 40: loadImage(false, true); break; case 38: loadImage(false, false); break; case 37: loadImage(true, false); break; } } public void changeDir(File dir) { this.dir = dir; } public void loadImage(boolean isFileA, boolean increase) { File[] fileList = dir.listFiles(new FilenameFilter() { public boolean accept(File dir, String name) { if (name.toLowerCase().endsWith(".dcm") || name.toLowerCase().endsWith(".dc3") || name.toLowerCase().endsWith(".dic")) { return true; } else { return false; } } }); if (fileList.length < 2) { return; } try { if (isFileA) { a_os = increase? (a_os + 1) % fileList.length : (a_os - 1 + fileList.length) % fileList.length; } else { b_os = increase? (b_os + 1) % fileList.length: (b_os - 1 + fileList.length) % fileList.length; } String ext = fileList[a_os].getName().substring(fileList[a_os].getName().lastIndexOf(".") + 1); Iterator readers = ImageIO.getImageReadersByFormatName(ext); ImageReader reader = (ImageReader) readers.next(); reader.setInput(new FileImageInputStream(fileList[a_os]), true); imgA = ((DICOMImageReader) reader).read(0, null); ext = fileList[b_os].getName().substring(fileList[b_os].getName().lastIndexOf(".") + 1); readers = ImageIO.getImageReadersByFormatName(ext); reader = (ImageReader) readers.next(); reader.setInput(new FileImageInputStream(fileList[b_os]), true); imgB = ((DICOMImageReader) reader).read(0, null); w = Math.max(imgA.getWidth(), imgB.getWidth()); h = Math.max(imgA.getHeight(), imgB.getHeight()); } catch (Exception e) { String fileName; fileName = isFileA ? fileList[a_os].getPath() : fileList[b_os].getPath(); promptError(fileName + " could not be read"); e.printStackTrace(); System.exit(1); } dx = w / 2; dy = h / 2; } public void promptError(String msg) { JOptionPane.showMessageDialog(null, msg, "Error", JOptionPane.ERROR_MESSAGE); } public void keyTyped(KeyEvent e) { } Trying to create an eBay listing template with a form on it. The form will allow the buyer to enter in their ebay ID, item number, and 3 choices. Form is complete, using this javascript for validation: Code: <SCRIPT language=javascript> function validate(){ var ebayid= document.getElementById('ebayid').value; var itemnumber= document.getElementById('itemnumber').value; var choice1= document.getElementById('choice1').value; var choice2= document.getElementById('choice2').value; var choice3= document.getElementById('choice3').value; if (!ebayid){ alert('Ebayid is required!'); document.getElementById('ebayid').focus(); return false; } if (!itemnumber){ alert('Item Number is required!'); document.getElementById('itemnumber').focus(); return false; } if (!choice1){ alert('Choice 1 is required!'); document.getElementById('choice1').focus(); return false; } if (!choice2){ alert('Choice 2 is required!'); return false; } if (!choice3){ alert('Choice 3 is required!'); return false; } return true; } </SCRIPT> I like this because it gives a pop up alert box (with definition) if a field is left empty. Upon success though the user is redirected off the page to a success page. I was told that this has to happen because the .php for the form to work is hosted on my site and the user needs to be redirected to my site in order for the form to work. Since this is the case, I was told I could use javascript to open up a separate window for this to happen, thus allowing the buyer to stay on the eBay listing (and to stay compliant with eBay's html/javascript policy). I have pieced together code from numerous forums to actually do this but there is one flaw. Code: <form action="http://www.mysite.com/test.php" method="post" name="testform" id="testform" onsubmit="window.open('', 'success', 'width=450,height=300,status=yes,resizable=yes,scrollbars=yes'); javascript:return validate();" rel="nofollow" target="success"/> This code not only opens a new window but it opens the new window on any click to the submit button, even if the validation fails. How do I write this so that the new window is only opened when the validation completes all true and not when the validation returns an error/alert box? Additionally... how do I add to the javascript so that the field "ebayid" requires 6 characters and the "itemnumber" requires 12 numbers? I would also like for the form itself to erase after a successful submission to prevent the user from hitting the submit button 100's of times spamming me with email (if it's possible) Thanks Kemble hi guys. im new to javascript and i require some help on a task so hoping someone on here could help me and possibly push me in the right direction. so i have a website with content on specific pages i need some sort of JS soloution which will fetch an ID/Keyword out of the page content so when a button is clicked it finds the ID/keyword and directs the user to a specific form/page. is this possible and can any1 help? Cheers, Ant. I have a simple js script which toggles between 2 tabs using a simple switch function to display: block or none. In each tab I have a form which returns data from a db using php mysql. The problem is that when I click the submit button the page is reloaded and so the page reverts to showing the 1st tab. The data is returned correctly but the users has to click the 2nd tab to view it. I have tried adding on onclick event to the submit button but this doesn't work. Is it possible to force the 2nd tab to show if the submit button in the 2nd tab is clicked. Many thanks! Hello, First, thank you to anyone that can help. Basically I am trying to create a Cascade Dropdown with a submit button, that once clicked, takes them to a URL depending on the choices they made in the cascade dropdown. I have the cascade dropdown working properly but do not know how to create a submit button that says, "If Cookeville = Cosmetology; then go to this URL." Any ideas or suggestions? I will need to create this type of conditional statement for each choice. My code so far is below. Thank you again in advanced. Code: <form id="locations"> <label for="categories">categories: </label> <select name="categories" id="categories"> <option value="1">Cookeville, TN</option> <option value="2">Lebanon, TN</option> <option value="2">Dalton Beauty School</option> <option value="2">Daphnie</option> </select> <label for="items">items: </label> <select name="items" id="items" type="submit"> <option class="2" value="0">Cosmetology</option> <option class="2" value="1">Cosmetology Instructor</option> <option class="2" value="2">Instructor Trainee</option> <option class="1" value="3">Cosmetology</option> <option class="1" value="4">Cosmetology Instructor</option> <option class="1" value="5">Esthetician</option> <option class="1" value="6">Instructor Trainee</option> <option class="1" value="7">Nail Technology</option> </select></form> <script type="text/javascript"> //Applies cascading behavior for the specified dropdowns function applyCascadingDropdown(sourceId, targetId) { var source = document.getElementById(sourceId); var target = document.getElementById(targetId); if (source && target) { source.onchange = function() { displayOptionItemsByClass(target, source.value); } displayOptionItemsByClass(target, source.value); } } //Displays a subset of a dropdown's options function displayOptionItemsByClass(selectElement, className) { if (!selectElement.backup) { selectElement.backup = selectElement.cloneNode(true); } var options = selectElement.getElementsByTagName("option"); for(var i=0, length=options.length; i<length; i++) { selectElement.removeChild(options[0]); } var options = selectElement.backup.getElementsByTagName("option"); for(var i=0, length=options.length; i<length; i++) { if (options[i].className==className) selectElement.appendChild(options[i].cloneNode(true)); } } //Binds dropdowns function applyCascadingDropdowns() { applyCascadingDropdown("categories", "items"); //We could even bind items to another dropdown //applyCascadingDropdown("items", "foo"); } //execute when the page is ready window.onload=applyCascadingDropdowns; </script> Is it possible for JavaSscript to toggle a submit button? I will be using it in this code: Code: <SCRIPT type="text/javascript"> if (document.forms["form"]["quantitys"].value > '.$row['quantity'].') { alert ("The quantity you wanted for product '.$row['id'].' is no longer available and will be changed to the highest available quantity."); document.forms["form"]["quantity"].value = '.$row['quantity'].'; // JAVASCRIPT TOGGLE SUBMIT } </SCRIPT> The submit button: <INPUT name="submit" type="submit" value="UPDATE QUANTITY"> Hi, i'm sabrina from Asia. i'm new here and a new student in javascript. My english language is not fluent.i'm really sorry about that. i really need help in my assignment. i've already create a form that will pop up an alert message if there is an empty input. it went great. but after i edit <form onSubmit="return formValidator()"> to <form onSubmit="return formValidator()" action="html_form_submit.asp" method="get"> i don't know why my submit button cannot send this form to html_form_action.asp. Please help me.. below is the code that i've done so far..thank you. <html><head> <title>Kelab ICT OUM</title> </head> <body> <script type="text/javascript"> function formValidator(){ var nama=document.getElementById("nama"); var umur=document.getElementById("umur"); var tarikh=document.getElementById("tarikh"); var poskod=document.getElementById("poskod"); var email=document.getElementById("email"); var alamat=document.getElementById("alamat"); var negeri=document.getElementById("negeri"); if(isAlphanumeric(nama,"Sila isi nama anda")){ if(isNumeric(tarikh,"Sila isi tarikh lahir")){ if(isNumeric(umur,"Sila isi umur")){ if(isNumeric(poskod,"Sila isi poskod")){ if(emailValidator(email,"Sila isi email anda")){ if(lengthRestriction(alamat,"Sila masukkan alamat anda")){ if(madeSelection(negeri,"Sila pilih Negeri")){ return true; } } } } } } } return false; } function notEmpty(elem, helperMsg){ if(elem.value.length=0) { alert(helperMsg); alem.focus(); return false; } return true; } function isNumeric(elem, helperMsg){ var numericExpression = /^[0-9]+$/; if(elem.value.match(numericExpression)) { return true; }else{ alert(helperMsg); elem.focus(); return false; } } function isAlphanumeric(elem, helperMsg){ var alphaExp=/^[0-9a-zA-Z]+$/; if(elem.value.match(alphaExp)) { return true; }else{ alert(helperMsg); elem.focus(); return false; } } function emailValidator(elem, helperMsg){ var emailExp=/^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zAz0-9]{2,4}$/; if(elem.value.match(emailExp)) { return true; }else{ alert(helperMsg); elem.focus(); return false; } } function lengthRestriction(elem,helperMsg){ var uInput=elem.value; if(uInput.length>15) { return true; } else{ alert(helperMsg); elem.focus(); return false; } } function madeSelection(elem, helperMsg){ if(elem.value == "Pilih") { alert(helperMsg); elem.focus(); return false; } else{ return true; } } </script> <form onSubmit="return formValidator()" action="html_form_submit.asp" method="get"> <table border="1" cellpadding="10" width="300"> <tr> <td colspan="3"><h1>Kelab iCT OUM</h1></td> </tr> <tr> <td>Nama</td> <td colspan="3"><input type="text" size="80" id="nama"</td> </tr> <tr> <td>Jantina</td> <td><input type= "radio" Name="Jantina" id="Jantina" value="p">Perempuan <br><input type= "radio" Name="Jantina" id="Jantina" value="l">Lelaki</td> <td>Umur <input type="text" size="10" id="umur"> Tahun <br><br> Tarikh Lahir <input type="text" size="10" id="tarikh"> </tr> <tr> <td>Alamat</td> <td><textarea name= "comments" rows="6" cols="20" wrap="virtual" id="alamat"> </textarea></td> <td>Poskod <input type="text" size="10" id="poskod"> <br><br>Negeri <select name= "negeri" id = "negeri"> <option value="Pilih" selected="select">Pilih</option> <option value="Perlis">Perlis</option> <option value="Kedah">Kedah</option> <option value="Perak">Perak</option> <option value="Selangor">Selangor</option> <option value="Negeri Sembilan">Negeri Sembilan</option> <option value="Melaka">Melaka</option> <option value="Kelantan">Kelantan</option> <option value="Pahang">Pahang</option> <option value="Terengganu">Terengganu</option> <option value="Johor">Johor</option> <option value="Wilayah Persekutuan">Wilayah Persekutuan</option> <option value="Sabah">Sabah</option> <option value="Sarawak">Sarawak</option> </select> <br><br>Email <input type="text" size="10" id="email"></td> </tr> </table><br> <input type="submit" value="Submit"> <input type= reset value ="Reset"> </form> </body> </html> Is there a way so that I can move the submit button outside of the form tags? and if this is possible, can you make it with multiple text boxes, each with their corresponding submit button? heres the coding Code: <html> <head> <script type="text/javascript"> <!-- function gotoURL() { var newURL = document.url2go.go.value document.location.href=newURL } //--> </script> </head> <body> <form action="javaScript:gotoURL()" method="get" name="url2go"> <input type="text" name="go" value="http://" size="50"> <INPUT TYPE="image" SRC="" id="go" HEIGHT="150" WIDTH="150" BORDER="0" ALT="Submit Form"> </form> </body> </html> Here is the code for test.html: Code: <html> <head><title></title></head> <body> <script type="text/javascript"> function OnSubmitForm(){ document.myform.action ="insert.html"; return true; } </script> <form name="myform" onsubmit="return OnSubmitForm()" method="get"> <input type='radio' name='Search' value='test'>test</input> </form> <a href='javascript:document.myform.submit()'><img src='images/buttonnext.jpg'></a> </body> </html> The way I want it to work: when the img (buttonnext.jpg) is clicked, the form is submitted. When the form is submitted it runs the javascript, which sets the action to be that insert.html is loaded. i.e. the end result should be to redirect to insert.html?Search=test The way that it is working now: the page is redirected to test.html?Search=test Note: If I use a submit button that is part of the form (i.e. input field with type "submit") the page is redirected correctly. What do I need to change to accomplish my goal? I am wondering if it is possible for me to replace my form submit button with an animated gif (fake progress bar), after the button has been pressed. Having so far disabled the button onclick, I would instead be happy if I could simply change the button text from 'Click here to submit' to 'Processing...' I have done some searches here but I'm finding references to innerHTML, etc., and I'm getting lost now. Is this an easy thing to do? TIA Hello, I have two frames, one to the left, one to the right. The left one contains a form, which I'm using to take in user input, and at the same time to refresh the frame on the right. The left frame's code is: Code: <html> <head> <script type="text/javascript"> function reload_right_frame() { parent.right_frame.location.reload(); } </script> </head> <form method="post"> <input type="submit" value="Enter" onClick="reload_right_frame();"> <input type='text' name='userinput'> </form> <?php echo "You entered: " . $_POST['userinput']; ?> </html> This succeeds in spewing out what the user entered, and simultaneously refreshing the right-hand frame. However, I want there to be a delay in refreshing the right-hand frame, so I changed the left-frame coding as follows: Code: <html> <head> <script type="text/javascript"> function delayed_reload() { var t=setTimeout("reloadframe()",3000); } function reload_right_frame() { parent.right_frame.location.reload(); } </script> </head> <form method="post"> <input type="submit" value="Enter" onClick="delayed_reload();"> <input type='text' name='userinput'> </form> <?php echo "You entered: " . $_POST['userinput']; ?> </html> This is where it stops working. The right-hand frame is not reloaded at all. I want it to reload after 3 seconds. The user input text is spewed out, though. If I change the input type from "submit" to "button", however, the delayed reload of the right-hand frame works fine, but then the user input text fails to show. How can I make both form and delayed reload both work? I'm probably missing something obvious. Thanks in advance for any help! 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> Friends, I want a simple contact form of 3 fields on my website which emails data on my email address or write a file on my server or just other any way inform me that data. But I dont want that "submit" button redirects to other 'thankyou' page where code is located. Plzzzzzzzz suggest or tell me what I have to do?? Hello All. What my script does is if you do not select a radio button and you hit submit an error will pop up saying please select game1. this is taken from the name of the radio button.. How can i make it so it prints out the VALUES of the 2 radio buttons. end result should print please select Baltimore Ravens vs. Cincinnati Bengals rather than please select game1. Code: function isChecked(radgrp) { var i = radgrp.length; do if (radgrp[--i].checked) return true; while (i); return false; } function validateTest(els) { var focus_me = null, msg = ""; if (!isChecked(els.game1)) { msg += " Game #1\n"; focus_me = focus_me || els.game1[0]; } if (!isChecked(els.game2)) { msg += " Game #2\n"; focus_me = focus_me || els.game2[0]; } if (!isChecked(els.game16)) { msg += " Game #16\n"; focus_me = focus_me || els.game16[0]; } if (msg != "") { var prefix = "\n WARNING: The following Games(s) were not selected:\n\n"; var suffix = "\nClick OK to submit your picks anyway.\n\n"; var suffix = suffix + "\n Click CANCEL to correct your picks." var ask = confirm(prefix + msg + suffix); if (ask) { if (focus_me) focus_me.focus(); return true; } else{ return false; } } } Here is the radio button. If you dont select the radio button i want the javascript validation pop but to say "please select Baltimore Ravens vs. Cincinnati Bengals rather than game1 like it does now. Code: <INPUT TYPE=RADIO NAME="game1" VALUE="Baltimore Ravens">Baltimore Ravens<BR> <INPUT TYPE=RADIO NAME="game1" VALUE="Cincinnati Bengals">Cincinnati Bengals<BR> Thanks |