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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

submit input disabled till user enters text in a form field

Status
Not open for further replies.

dude2001

Programmer
Apr 15, 2005
2
US
at they have a script that doesnt let you submit the form till it is filled n, I'm wondering if anyone knows of an easyer script like this that does basicly the same thing, it looks like it uses DOM
Code:
[URL unfurl="true"]http://spaces.msn.com/signup.js[/URL]

function cc()
{
 var o = document.getElementById("ca");
 if (null != o)
 {
 o.value = "1";
 }
 return true;
}




<input id="ca" type="hidden" value="0" name="ca">


<button value="Create your space" type="submit" id="CreateSpace" name="CreateSpace" onclick="return cc();" disabled="disabled">


but the problem with this script is if the user has javascipt disabled they will npt be able to sumit the form due from disabled="disabled" on it
 
There is no way do prevent a form from being submitted until all fields are filled in unless you have javascript enabled.

If you want to allow people without javascript enabled to go ahead and submit the form without checking, take out the disabled setting in the button tag, and disable it in an onload function. That way if javascript is disabled the but will not get disabled, but if javascript is enabled the button will be disabled.


Tracy Dryden

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard. [dragon]
 
There is no way do prevent a form from being submitted until all fields are filled in unless you have javascript enabled."


no, you misread what I wrote or was meaning, see by using:

<button value="Create your space" type="submit" id="CreateSpace" name="CreateSpace" onclick="return cc();" disabled="disabled">

the button is disabled, with or without javascript

now the script i posted above allows the button to be submitted on only if the user has javascript, i want to find a js script that does need to use disabled="disabled" on it, that way if the user doesnt have js enabled it will still let them submit the form

 

What you want is a standard form validation script, then. Use the onsubmit event handler of the form to check your data, and harness the return value to allow / block the form submission... something like this:

Code:
<script type="text/javascript">
<!--
   function validateForm() {
      // return true if form validates, false otherwise
   }
//-->
</script>

...

<form onsubmit="return(validateForm());">

If users have JS disabled, the form will always submit, so you should do some server-side checking as well.

Hope this helps,
Dan


[tt]D'ya think I got where I am today because I dress like Peter Pan here?[/tt]
[banghead]

 
Did you read the rest of my post?
If you want to allow people without javascript enabled to go ahead and submit the form without checking, take out the disabled setting in the button tag, and disable it in an onload function. That way if javascript is disabled the but will not get disabled, but if javascript is enabled the button will be disabled.

Tracy Dryden

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard. [dragon]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top