JavaScript - Disable Submit Button After Onclick
All,
I have the following code: Code: <input type="button" name="button" value="Submit" onclick="javascript:get(this.myform);"> How can I change this to make this button disabled after the onclick? Thanks in advance. Similar TutorialsHello 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 have created some online software which uses form data to submit to another page. The problem is that I have other submit buttons in the same form which submit to different pages (depending on which button is pressed). The first submit button works fine but all the others only work once. Code: <input class="cssbutton" type='submit' value='Button1' onclick="wbform.action='page1.php'; target='mainFrame'; return true;"> <input class="cssbutton" type='submit' value='Button2' onclick="wbform.action='page2.php'; target='_blank'; return true;"> <input class="cssbutton" type='submit' value='Button3' onclick="wbform.action='page3.php'; target='topFrame'; return true;"> <input class="cssbutton" type='submit' value='Button4' onclick="wbform.action='page4.php'; target='topFrame'; return true;"> <input class="cssbutton" type='submit' value='Button5' onclick="wbform.action='page5.php'; target='_blank'; return true;"> <input class="cssbutton" type='submit' value='Button6' onclick="wbform.action='page6.php'; target='_blank'; return true;"> Any ideas my friends? 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> I'm trying to get a submit button to open a thank you page I created (i.e. thankyou.html) only after the user has filled out a series of questions for a form. If they don't fill out the required information, a pop up box informs them to fill out the section (this I have accomplished). I cannot get the submit button to not work if the fields are left un-answered. Can you guys help? Thanks for you help. -------------------------------------------------------------------------- This is what I have so far: <title>Customer Demographic Data Form</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" ></meta> <style type="text/css"> body { font-family: Times New Roman; color: navy; background-color: #CCC } h1, h2, h5 { font-family: Times New Roman; color: black } body,td,th { color: #000; font-family: Times New Roman, Times, serif; } h1 { color: #000; } h2 { color: #000; } h5 { color: #000; } a { font-family: Times New Roman, Times, serif; } h1,h2,h3,h4,h5,h6 { font-family: Times New Roman, Times, serif; } </style> <script type="text/javascript"> function checkForNumber(fieldValue) { var numberCheck = isNaN(fieldValue); if (numberCheck == true) { window.alert("Please enter a numeric value!"); return false; } } function confirmSubmit() { var email = document.forms[0].email.value; if (document.forms[0].fname.value == "" || document.forms[0].lname.value == "") { window.alert("Please enter your first and last name."); document.forms[0].lname.focus(); return false; } else if (document.forms[0].address1.value == "" && document.forms[0].email.value == "") { window.alert("Please enter your Mailing Address or Email Address!"); document.forms[0].address1.focus(); return false; } else if (email.indexOf("@") == -1 && document.forms[0].email.value != "") { window.alert("Please enter a valid e-mail address."); document.forms[0].email.focus(); return false; } else if (email.indexOf(".") == -1 && document.forms[0].email.value != "") { window.alert("Please enter a valid e-mail address."); document.forms[0].email.focus(); return false; } else if(document.forms[0].city.value == '') { window.alert("Please enter your City"); document.forms[0].city.focus(); return false; } else if(document.forms[0].state.value == '') { window.alert("Please enter your State"); document.forms[0].state.focus(); return false; } else if(document.forms[0].zip.value == '') { window.alert("Please enter your Zip Code"); document.forms[0].zip.focus(); return false; } checkCookie() } function checkCookie() { var formInfo = decodeURI(document.cookie); var userInfo = formInfo.split("; "); var lname = userInfo[0].split("="); var fname = userInfo[1].split("="); if (lname[1] == document.forms[0].lname.value && fname[1] == document.forms[0].fname.value) { this.close(true); window.open("FormDenied.html"); return false; } else { setCookie(); return true; } } function setCookie() { var expiresDate = new Date(); expiresDate.setFullYear(expiresDate.getFullYear() + 1); document.cookie = encodeURI("lname=" + document.forms[0].lname.value) + "; expires=" + expiresDate.toUTCString(); document.cookie = encodeURI("fname=" + document.forms[0].fname.value) + "; expires=" + expiresDate.toUTCString(); window.alert("Your information has been saved."); } </script> </head> <body> <p> </p> <h1 align="left" style="text-align: left">Kudler Fine Foods contact form</h1> <form action="" method="get" enctype="application/x-www-form-urlencoded" onsubmit="return confirmSubmit();" onreset="return confirmReset();" > <blockquote> <h2><u>Name</u></h2> <p> <input type="text" name="fname" id="fname" size="25" /> <label for="fname"><strong>First Name</strong><br> <br> </label> <input type="text" name="lname" id="lname" size="15" /> <strong>Last Name</strong></p> <h2>---------------------------------------<br> <u>Address</u> </h2> <p> <input type="text" name="address1" id="address1" size="30" /> <label for="address1"><strong>Address Line 1</strong></label> </p> <p> <input type="text" name="address2" id="address2" size="20" /> <strong>Address Line 2<br> <br> </strong> <input type="text" name="city" id="city" size="20" /> <strong>City</strong> </p> <p> <input type="text" name="state" id="state" size="2" /> <label for="state2"><strong>State</strong></label> </p> <p> <input type="text" name="zip" id="zip" size="10" maxlength="10" onChange="return checkForNumber(this.value);" /> <label for="zip2"><strong>Zip Code</strong></label> </p> <h2>--------------------------------------- </h2> <h2> <u>Other Information</u></h2> <table> <tr> <td width=300><strong>Telephone</strong></td> <td width=300><p><strong>Email address:</strong></p></td> </tr> <tr> <td> <input type="text" name="area" id="area" size="3" maxlength="3" onChange="return checkForNumber(this.value);" /> <input type="text" name="exchange" id="exchange" size="3" maxlength="3" onChange="return checkForNumber(this.value);" /> <input type="text" name="phone" id="phone" size="4" maxlength="4" onChange="return checkForNumber(this.value);" /></td> <td> <input type="text" name="email" id="email" size="30" /></td> </tr> </table> </blockquote> <h5> </h5> <blockquote><blockquote> <h3 align="center"> <input name="Submit" type="button" </h3> </blockquote> </blockquote> </form> </body> </html> Below is a script I found at http://bytes.com/topic/javascript/an...cookie-problem The idea is a like button, like on fb, in a form which updates a db field I can use to display the number of likes, and my goal is to disable the like button for the rest of the session, or a day, or whatever. This script disables it onclick, the problem is I can't figure out how to get it to submit the form as well. I have found it does submit if the input type is 'submit', but then it doesn't call the disable function. I tried writing another function to submit the form but no go. Code: <html> <head> <title>Vote Button</title> <script type="text/javascript"> function checkForVote() { // If there is a cookie... if(document.cookie != "") { if(getCookie("voted") == 1) { // Disable the button again if user already voted. disableButton(); } } } function disableButton() { var submitvote = document.getElementById("submitvote"); submitvote.disabled = true; submitvote.value = "You Already Voted."; } function setCookie(name, value, days) { if(days) { var date = new Date(); date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000)); var expires = "; expires = " + date.toGMTString(); } else { var expires = ""; } document.cookie = name + "=" + value + expires + "; path=/"; // Disable the button as soon as the user clicks it. disableButton(); } function getCookie(name) { var nameEQ = name + "="; var ca = document.cookie.split(';'); for(var i=0; i < ca.length; i++) { var c = ca[i]; while (c.charAt(0)==' ') { c = c.substring(1,c.length); } if (c.indexOf(nameEQ) == 0) { return c.substring(nameEQ.length,c.length); } } return null; } </script> </head> <body> <form name="voteform" id="voteform" action="foo.php" method="post"> <input type="button" name="submitvote" id="submitvote" onclick="setCookie('voted', 1, -1);" value="Submit Vote"/> </form> </body> <script type="text/javascript"> // Run checkForVote() at end of document so that form and contents can be referenced window.onload = checkForVote(); </script> </html> Is it possible disable an onclick after clicking it and then enable it from another onclick by id Code: <img id="one" href="images/homepage/sliders/bonus_button.jpg" style="position:relative; top:30px; left:50px; height:30px; width:70px; float:left;"> This code runs when it is clicked: Code: $("#one").click(function() { runEffectB(); return false; }); What I would like to happen is for either runEffectB() to not run if it was just run or to disable the #one.click once it has run. I am assuming I will be able to re-enable it from another onclick running a similar function. This is jquery and jquery ui if that helps. Any ideas much appreciated. 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? Someone helped me earlier with this script that sets a 10 second timeout on a submit button once it's pressed. After 10 seconds the "disabled" attribute is removed and is added back when a user presses the button. Code: function enable() { var x = document.getElementById("reload"); x.disabled = false; } function disable() { var x = document.getElementById("reload"); $(function(){ $('#tagwallMessages').load('member/tagwall_load.php'); }); x.disabled = true; setTimeout('enable()', 5000); } Code: <input type="button" id="reload" onclick="disable()" value="Click!" /> However, I am now setting up the page with images (the input button is too plain and ugly). I have two images for when the "disabled" attribute is being added and removed, how can I make the script swap between these two? My first image says "SUBMIT" - the other image is the same, but faded out a bit, giving it the "disabled"-button-feeling. Help is appreciated. Within my project, using PHP/HTML/Javascript, I am trying to set up a page where a corresponding submit button is enabled when a given checkbox is checked. What complicates my attempt is that the checkboxes and submit buttons are in the form of arrays. Here is a snippet of my code: Code: <form name="myform4" id="list_apps" method="post"> <?php for ($i=0; $i<$num_rows;$i++) { ?> <p> <input type="checkbox" name="app[]" id="app[]" onclick="enable_perm()"> <input name="set_perm[]" type="submit" id="set_perm[]" value="Set Permissions"> </p> <?php } </form> Here is my attempt at using Javascript to disable the first submit button after clicking any check box: Code: function enable_perm() { document.myform4.set_perm[0].disabled = true; } What am I missing here, or, how do I enable/disable submit buttons that are part of an array? How can I make this code disable the submit button once it has been pressed, then if the user hits back or GOES back, it will re-enable it again? Code: <SCRIPT LANGUAGE="JavaScript" TYPE="text/JavaScript"> function formControl(submitted) { if(submitted=="1") { commentForm.Submit.disabled=true alert("Thanks for your comments!") } } </SCRIPT> Thanks! ShadowIce~ Hello Friends, i have a small problem and need your help. I have a form with 4 radio buttons, the scenario is, when a user click on a radio button a hidden content will be displayed and the other three radio buttons will be disabled so that at one time a user can only click and view single radio button and the hidden content. Here is my code to show hide the hidden content but i need when the user select one radio button the other radio buttons should disable. <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>test</title> <style type="text/css" media="screen"> .hide{ display:none; } </style> </head> <body> <div id="tabs"> <div id="nav"> <p>Show Div 1:<input type="radio" name="tab" value="value1" class="div1" /></p> <p>Show Div 2:<input type="radio" name="tab" value="value2" class="div2" /></p> <p>Show Div 3:<input type="radio" name="tab" value="value3" class="div3" /></p> <p>Show Div 4:<input type="radio" name="tab" value="value4" class="div4" /></p> </div> <div id="div1" class="tab"> <p>this is div 1</p> </div> <div id="div2" class="tab"> <p>this is div 2</p> </div> <div id="div3" class="tab"> <p>this is div 3</p> </div> <div id="div4" class="tab"> <p>this is div 4</p> </div> </div> <script type="text/javascript" charset="utf-8"> (function(){ var tabs =document.getElementById('tabs'); var nav = tabs.getElementsByTagName('input'); /* * Hide all tabs */ function hideTabs(){ var tab = tabs.getElementsByTagName('div'); for(var i=0;i<=nav.length;i++){ if(tab[i].className == 'tab'){ tab[i].className = tab[i].className + ' hide'; } } } /* * Show the clicked tab */ function showTab(tab){ document.getElementById(tab).className = 'tab' } hideTabs(); /* hide tabs on load */ /* * Add click events */ for(var i=0;i<nav.length;i++){ nav[i].onclick = function(){ hideTabs(); showTab(this.className); } } })(); </script> </body> </html> Thank you for your help in advance. I am making a simple puzzle game on Android using Phonegap, that is HTML5, CSS3 and JavaScript. When a user fills an answer on a page, if the answer is correct, it will go to another page. However, once the user goes to the next page, he/she CANNOT return back to the previous page. I do not want the user to return back, else he/she will have to fill the answer again to go to the next page, so it's not good. Thank Hi I have the following code...
Code: <!doctype html> <html> <head> <title>Loops</title> </head> <body> <form id = "frmOne"> <table border="1" > <p>Items Remaining: <a id="clicks">5</a></p> <tr> <th> Number One:</th> <th> Number Two:</th> </tr> <tr> <td> <Input Type="Text" Name="txtFirstNumber" Size="5" value=""> </td> <td> <Input Type="Text" Name="txtSecondNumber" Size="5" value=""> </td> </tr> <tr> <td colspan="2"> Totals: <textarea Name="totals" style="width: 400px; height: 300px;"></textarea></td> </tr> <tr> <td colspan="2"> <Input Type="Button" Name="b1" Value="Add Numbers" onClick = calculate()> </td> </tr> </table> </form> <script> var Totals = [ ]; var clicks = 5; function calculate() { var form = document.getElementById("frmOne"); var A = form.txtFirstNumber.value; var B = form.txtSecondNumber.value; Totals.push( A + " + " + B + " = " + (1*A+1*B) ); form.totals.value = Totals.join("\n"); form.txtFirstNumber.value = form.txtSecondNumber.value = ""; clicks -= 1; document.getElementById("clicks").innerHTML = clicks; } </script> </body> </html> I want to add in an if statement that checks to see if the number of items remaining is 0. If it is 0, I want it to say finished and the button be disabled / disappear. Can anyone help? TIA Hi, Well I wanted to ask that how to disable the function of hide button in meebo bar, its that small arrow like button on the right side, which is when clicked hides meebo bar, I want to disable it, so that even if it is clicked it doesn't hide the bar. To see the bar you can visit http://www.meebo.com/websites Hi guys, At the moment i have this code which disable the middle button in Safari and Chrome.. Code: $('body').mousedown(function(e){ if(e.button==1) return false } ); How can I disable it in Firefox and IE?.. i think IE middle button ==4 but its not working for me. Thanks in advance! Hi, I have a button with a class name as below: <input type="button" class="test" value="Add" onclick=Dothis(this);> class test { background-image: url("test.png"); } I would like to disable the button when clicked function Dothis (element) { element.disabled = 'true'; } This is working fine (i'm seeing it as disabled(grayedout)) when i wont set any class. But when i set the class to "test" i'm not seeing any change. Can you please let me know how i can resolve this. Hi Experts .. not sure if this is the right forum. However here is my question: I have a date field with 25 values (prepopulated Radio Buttons) where we are asking the members to select one day to volunteer. Once a member selects a day we would like to disable that Radio button value (Greyed out) for other members. So basically out of 25 available days we would like to disable values as soon as a member selects one. The field is on a classic ASP form with SQL Server backend. How can I accomplish the above? Please advice. Regards Vinny Hi, I have two buttons save and finish. I want to enable the button finish whenever I click the save button. page1.jsp. <script> InitialLoad() { document.getElementById('finish').disabled = true; } save(){ document.getElementById('finish').disabled = false; } </script> <html> <body onload= "InitialLoad()"> <input type="submit" name="finish" id=="finish" value="finish"> <input type="submit" name="save" value="save" onclick= save();> </body> </html> strutsconfig.xml <forward name="success" path="atre.dodUpgrade.show.page1"/> Using the above I can enable it temporarly. But whenever I call the forward page it on action class forward = mapping.findForward("success"); The Problem is page Refresh again and it shows disabled button for finish. what could be the solution for this? Thanks hello, i have this script that doesn't work exactly right yet. but i can't figure it out what i need to chance to let it work. in the script i want the button to be enabled when both text boxes are filled, atm when i fill in 1 it will already enable the button and thats exactly what i don't want. im quite a nooby in this so could some1 help me ? tyvm in advance code___________________ <html> </head> <script type="text/javascript"> function ButtonDisable1(text) { if (text.length > 0) document.getElementById("submit_button").disabled = false; else document.getElementById("submit_button").disabled = true; } </script> </head> <body> <input type="text" id="search_text" onchange="ButtonDisable1(this.value)"> <input type="text" id="search2_text" onchange="ButtonDisable1(this.value)"> <input type="submit" id="submit_button" value="Search" disabled="true"> </body> </html> hi again hi i want to create a form Form have 2 submit buttons also have one drop down list when selecting dropdown list item disable the one submit button plzzzzzz help m for do this with sample code needed. |