0

My form.html

<form id="search-form" method="post" action="." name="f">
<p><label for="id_customer_type">Customer type</label> <select name="customer_type" id="id_customer_type">
<option value="">All</option>
<option value="TDO" selected="selected">TDO</option>
</select></p>
<p><label for="id_tag">Tag</label> </p><dl>
<dt><strong>School</strong></dt>
<dd><label for="id_tag_1"><input checked="checked" name="tag" value="2" id="id_tag_1" type="checkbox"> Private</label></dd>

<dd><label for="id_tag_2"><input checked="checked" name="tag" value="3" id="id_tag_2" type="checkbox"> Public</label></dd>
</dl> 
<input id="filter" value="Filter" type="submit"> 
</form>

My script.js

 $(document).ready(function(){
       // Third way == UPDATE jQuery 1.3
       $("input[type='checkbox']:checked").each(function(){
            // your code
            checkboxs_ischecked = $("input[type='checkbox']").val();
        });

        $("#filter").click(function() {
            customet_type = $('#id_customer_type :selected').text();
            checkbox_ischecked = ????? //How Can I get the checkboxs value that is checked?
            document.f.action = "/customer/show/?customer_type="+customet_type+"&

    tag="+checkboxs_ischecked; // in my case something like this :checkbox_ischecked = Private_Public if I have checked Private and Public
                 ;
                return true; 
            });

        });

Thanks ! :)

1
  • Are you trying to make a radio button by any chance? Commented Dec 24, 2009 at 6:19

1 Answer 1

1

val() is the correct method, but the scope of checkbox_ischecked is not considered.

You have to declare the variable outside of the anonymous function:

$(document).ready(function(){

    var checkboxs_ischecked; // ADD THIS LINE

    $("input[type='checkbox']:checked").each(function(){
        checkboxs_ischecked = $("input[type='checkbox']").val();
    });

...
Sign up to request clarification or add additional context in comments.

1 Comment

This shouldn't work, since he's checking it on document.ready. The user might had modified the information before the submit, this piece of code should be IN the $("#filter").click() function.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.