How to grayen the input field and submit button

I want to omit these two things in the song input field and the submit button until the user logs in and executes. Is there an easy way to do this through jQuery.

artist input field id: #request_artist

+6
javascript jquery
source share
3 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); } }); 
+12
source share

for the input field, the submit button should be equal to $ ('# request_artist'). attr ('disabled', true);

+4
source share

The code for one liner will look like this:

  <input type="text" name="name" value="" id="txt1" /> <input type="button" name="name" id="btn1" disabled="disabled" value="Submit" /> <script type="text/javascript"> $("#txt1").keyup(function () { $("#btn1").attr("disabled", $.trim($("#txt1").val()) != "" ? "" : "disabled"); }); </script> 
+3
source share

All Articles