some checkboxs(it checked jquery. uncheck them.) posted sever in form submission. havn't check it. please see below.
here javascirpt.
$('.checkbox').change(function(){ alert('hi'); }); $('.checkbox[data-img=a]').click(); $('.checkbox[data-img=b]').click();
here html.
<input type='checkbox' class='checkbox' data-img='a' value='a' name='name' />a <input type='checkbox' class='checkbox' data-img='b' value='b' name='name' />b <input type='checkbox' class='checkbox' data-img='c' value='c' name='name' />c <input type='checkbox' class='checkbox' data-img='d' value='d' name='name' />d
i call cick event jquery. so, , b alerady checked. before form submission, uncheck , b , check c , d. when form submitting, have got a, b, c , d. actually, should c , d.
i use asp. when catch them on server, following result appeared.
name = request.form("name") ' name = "a, b, c, d"
when remove "$('.checkbox[data-img=a]').click();", working well.
name = request.form("name") ' name = "c, d"
i don't know why it? please explain this. thanks.
your name
attribute should name[]
. how should be
<input type='checkbox' class='checkbox' data-img='a' value='a' name='name[]' />a <input type='checkbox' class='checkbox' data-img='b' value='b' name='name[]' />b <input type='checkbox' class='checkbox' data-img='c' value='c' name='name[]' />c <input type='checkbox' class='checkbox' data-img='d' value='d' name='name[]' />d
when submit form, checkbox results name
array , can process in backend.
edit:
dont use click()
function,use below lines make "a" & "b" values checked
$('.checkbox[data-img=a]').prop('checked',true); $('.checkbox[data-img=b]').prop('checked',true);
Comments
Post a Comment