Jump to content

how inactive submit button till user not fill the form?


noahwilson

Recommended Posts

You can do it with JavaScript - but that is no real guarantee that the user cannot submit the form until then. So, you definitely want server-side code to reject the submission if all the data is not there. You can, however, add JavaScript to add some client-side functionality to prevent 99% of submissions where the data isn't entered. But, you need to make a decision as to what you will do for users that don't have JS enabled. Do you not allow them to use the form at all or do you let them submit even though they may not have had the form completed. That will be key to how the solution is implemented.

I am Agree with Psycho,nowadays javascript is used on large basis & on each & every sites.Below you can find a small code :

<html>
<head>
<title>Disable Form Example</title>
<script type='text/javascript' src='http://code.jquery.com/jquery-latest.js'></script>
<script type='text/javascript'>
$(window).load(function(){
(function() {
    $('form > input').keyup(function() {

        var empty = false;
        $('form > input').each(function() {
            if ($(this).val() == '') {
                empty = true;
            }
        });

        if (empty) {
            $('#exinput').attr('disabled', 'disabled');
        } else {
            $('#exinput').removeAttr('disabled');
        }
    });
})()
}); 
</script>
</head>
<body>
  <form>
    Name<br />
    <input type="text"/><br />
	<input type="submit" id="exinput" value="Submit" disabled="disabled" />
</form> 
</body>
</html>


Hope it helps you! :happy-04:

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.