Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do i grey out the input field and the submit button

I want to grey out these two things the song input field and the submit button until the user enters and artist. Is there an easy way to do this via JQuery.

the id of the artist input field is #request_artist

like image 837
Matt Elhotiby Avatar asked Sep 19 '10 14:09

Matt Elhotiby


People also ask

How do I disable input submit button?

1.1 To disable a submit button, you just need to add a disabled attribute to the submit button. $("#btnSubmit"). attr("disabled", true); 1.2 To enable a disabled button, set the disabled attribute to false, or remove the disabled attribute.

How disable submit button if input is empty?

Just click f12 in your browser, find the submit button in the html, and then remove the disabled ! It will submit the form even if the inputs are empty.

How do you GREY out a field in Javascript?

If you want to grey out, u can use the above one: document. myForm. myField.


1 Answers

You can do something like this:

var artist = ('#request_artist');
var song = ('#request_song');
var assubmit = ('#request_submit');

song.attr('disabled', true);
assubmit.attr('disabled', true);

artist.change(function() {
  if(artist.val() > 0) {
    song.attr('disabled', false);
    assubmit.attr('disabled', false);
  } else {
    song.attr('disabled', true);
    assubmit.attr('disabled', true);
  }
});
like image 50
xil3 Avatar answered Sep 27 '22 16:09

xil3