Wordpress Themes - Electric blanket - Free MP3 Downloads - Wordpress Theme - Self Improvement Articles Directory

PDA

View Full Version : disable submit button


bumbar
Sep 1st 2008, 2:33 am
Hallo!

Is it possible for the button for the sending only to be activated if the all fields to be completed?

I think that must be used getElementById['Login'].disable=true

But it is not obviously how... :(

Here the code:


<script type="text/javascript">

function check()

{

if(document.getElementById("username").value=="")

{

alert("Please, type username!");
return false

}

if(document.getElementById("password").value=="")
{
alert("Please, type password!");
return false
}

}
</script>

<form id="form1" name="form1" method="post" action="" onsubmit="return check()">
<label> Username:
<input type="text" name="username" id="username" />
<br />
Password:
<input type="text" name="password" id="password" />
<br />
<input type="submit" name="Login" id="Login" value="Submit" />
</label>
</form>


Thanx!

xlcho
Sep 1st 2008, 5:28 am
You have to return true if the input is correct. Just add a "return true;" at the end of check()

vasago
Sep 1st 2008, 5:43 am
Hi, Bumbar,

the property you need is disableD :)
Just add one "d" at the end;
Like this:

getElementById['Login'].disabled=true;

xlcho
Sep 1st 2008, 6:33 am
I totally missed the 'disabled' problem :o vasago is right about the property name, but i wonder why would you need to disable the button when your check() function is working just fine for stoping the form from submition (you just need to add 'return true' as i said before)...