Click here to Skip to main content
15,891,529 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
What I want to achieve is, when I enter a letter in the textarea or selecting an image with type='file' tag, then the button functionality or text should change automatically.

My problem is that, the change only will take action when I click on the button instead automatically.

What I have tried:

JSFiddle
Posted
Updated 20-Feb-19 0:54am
v3

1 solution

You're only running your check code on the submit click, you need to run it for other events you're interested in such as the textarea or file changing

$('#form').submit(function() {
	return validate();
});

$('#txtarea').keyup(function(){validate();});
$('#file').change(function(){validate();});

function validate()
{
  if ($.trim($("#txtarea").val()) !== "" || $.trim($("#file").val()) !== "") {
    $("#submit").html('proceed');
    return true;
  } else {
    //alert('something wrong');
    $("#submit").html('Not proceed');
    return false;
  }
}
 
Share this answer
 
Comments
Galarist_00 20-Feb-19 7:53am    
Thanks so much! That's what I am looking for!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900