Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

disable submit button when javascript is disabled

I have a form which needs javascript to be enabled for validation, is there a way to disable submit button when javascript is disabled and warn user to enable it first ?

like image 368
datisdesign Avatar asked Dec 27 '09 00:12

datisdesign


3 Answers

Disable it by default and use JavaScript to enable it.

<input type="submit" value="Submit" id="submitBtn" disabled />

<script type="text/javascript">
var _onload = window.onload || function()
{
  document.getElementById('submitBtn').disabled = false;
}

_onload();
</script>

That way, if JavaScript is disabled then the button will also remain disabled.

jQuery version:

<script type="text/javascript">
$(function(){
  $('#submitBtn').attr('disabled', false);
});
</script>
like image 179
Darrell Brogdon Avatar answered Oct 19 '22 19:10

Darrell Brogdon


Have it disabled by default and if there is javascript, then enable it.

like image 34
johnnyArt Avatar answered Oct 19 '22 18:10

johnnyArt


Don't define an HTML form action, but rather define only an onSubmit javascript event handler. If javascript is not enabled, the onSubmit will not fire, but since there is no form action, the submit button won't do anything either.

You could also opt to have the HTML form action go to an error page explaining that javascript must be enabled, so that the user has some sort of feedback.

Alternatively you can start with the button disabled (as other posters suggested). If you do that, you should also consider a message on the form indicating why the button is disabled. Remove that message with javascript if it is enabled at the same time you re-enable the button.

like image 2
Eric J. Avatar answered Oct 19 '22 18:10

Eric J.