Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Enable form button 1

Status
Not open for further replies.

apex82

Programmer
Mar 2, 2009
127
GB
At the moment I have a simple form containing text fields.

I want to change my form so when all the text fields have been filled in - it enables the submit button.

Does anyone know how to achieve this or any examples out there? I can’t find any.

Thanks.
 
Thanks guys.

The problem I’m having is all the examples I’ve seen enable the button with the use of a checkbox.

I’m struggling to enable the button with the use of a text boxes.

I want to be able to enable the button once all the text boxes have been completed.

Thanks.

 
This will check all "input" tags for a value within the form...

Code:
<script language="javascript">
	function checkform() {
		var allFilled = true; // let's assume everything is filled in
		var inputs = document.getElementById("myForm").getElementsByTagName("input");
		for (var i = 0 ; i < inputs.length ; i++) {
			if (inputs[i].value == "") {
				allFilled = false;
				break;
			}
		}
		
		if (allFilled) {
			document.getElementById("btnSubmit").disabled = "";
		} else {
			document.getElementById("btnSubmit").disabled = "disabled";
		}
	}
</script>

<form id="myForm">
	<input type="text" id="tbxOne" value="" onchange="checkform()" /><br />
	<input type="text" id="tbxTwo" value="" onchange="checkform()"  /><br />
	<input type="text" id="tbxThree" value="" onchange="checkform()"  /><br />
	<input type="submit" disabled="disabled" id="btnSubmit" value="Submit" />
</form>

--------
GOOGLE is a great resource to find answers to questions like "how do i..."

If you don't know exaclty what you want to do or what to search on, try Google Suggest: --------
I have recently been semi-converted to ensuring all my code (well most of it) works in both javascript and non-javasc
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top