dana
dana

Reputation: 5218

Jquery disable form button until click on a non form element

i have a simple list, that is not included in a form, and a form.

What i want to do: i want that the submit button of the form to be enabled only when someone clicks on one element of that list. Is this possible using jquery?

thank you!

Upvotes: 0

Views: 845

Answers (4)

thecodeparadox
thecodeparadox

Reputation: 87073

Try this. Here I used sample HTML.

HTML:

<form id="myform">
    <input type="text" />
    <input type="submit" disabled="disabled" />
</form>

JQUERY:

$('#list li').click(function(){
   $('#myform input:submit').attr('disabled',false);
});

Upvotes: 0

Xion
Xion

Reputation: 22770

Set the button to disabled initially (e.g. by adding disabled="disabled" directly in the HTML) and define appropriate action for click event of your list:

$("#the_list").bind("click", function() {
    $("#submit_button").removeAttr("disabled");
});

Upvotes: 1

mjspier
mjspier

Reputation: 6526

this works

<script src="http://code.jquery.com/jquery-1.5.1.min.js" type="text/javascript"></script>
<script type="text/javascript">
     $(document).ready(function() {

       $('#MyList').click(function() {
          $('#submitButton').removeAttr("disabled");
       });
    });
</script>

    <ul id="MyList">
     <li>element1</li>
     <li>element2</li>
    </ul>
    <input type="submit" id="submitButton" value="Submit" disabled="true">

Upvotes: 1

Khoa Nguyen
Khoa Nguyen

Reputation: 1317

You can do like this HTML

<ul id="list">
    <li>Item 1</li>
    <li>Item 2</li>
    <li>Item 3</li>
</ul>
<form>
    <input id="btnSubmit" type="submit" disabled="disabled" value="Submit"/>
</form>

Javascript

$(document).ready(function() {
    $('#list > li').click(function() {
        $('#btnSubmit').removeAttr('disabled');
    });
});

Demo: http://jsfiddle.net/ynhat/r6nUD/

Upvotes: 1

Related Questions