开发者

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!


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/


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">


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");
});


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);
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜