开发者

Changing form from $.post request result

开发者 https://www.devze.com 2023-02-21 08:13 出处:网络
here\'s my dilemma, I have a page, with a form on top. This form contains multiple checkboxes with the same name: \"Topic\". Each time I tick or untick one or more checkboxes it loads the resulting pa

here's my dilemma, I have a page, with a form on top. This form contains multiple checkboxes with the same name: "Topic". Each time I tick or untick one or more checkboxes it loads the resulting page in a div by using a $.post jquery request, like this:

$.post("index-main-list.php", $("#select开发者_如何学运维ors").serialize(), function(data){
$('#main-list').html(data); }); 

my form id being "selectors" and the result being loaded in the "main-list" div. So far, all of this works fine.

The page result loaded in the #main-list contains a list of articles corresponding to the topic the user chooses.

But in this list, every article has a link to his specific topic, what I would want those links to do, is to untick all boxes in the form that is on the page, and tick only the corresponding box, therefore triggering a new execution of the $.post request and therefore loading only the articles corresponding to the topic the user chose.

By using something like :

$('#selectors')[0].reset(); 
$('input[id=topic]').attr('checked', true);

But for some reason, I can't seem to change anything in the #selectors form, anyone might have an idea why? Thanks!


Are you looking for something like this?

$('input:checked').attr('checked', false); // uncheck all checked
$('input[id=topic]').attr('checked', true); // check only the specific box

Also, if #selectors is your form, then this will be more specific and perform a bit better:

$('#selectors').find('input:checked').attr('checked', false);
$('#selectors').find('input[id=topic]').attr('checked', true);
0

精彩评论

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