2013-07-05 50 views
0

嗨,我試圖讓一個複選框的值,並指定檢查所有網頁上相同的ID checkboxed值。但是我嘗試不工作,這裏是我在做什麼多值複選框jQuery的問題

 $('.add_button').click(function() { //they click a div named added 
     selected=$('#ssrBox').val(); //I get the id of the checkbox and the values however I only get one value. 
     id=$(this).attr('id'); //I find the id of the div which is ssrBox 
     $('#ssrBox').change(function() { // I find the rest of the checkboxes with the same id and hopefully make them select the same value 
     $('#ssrBox').add(selected); //have the value being checked for all 
     }); 



    <div class="grs-multi-select-area" style="height:120px;width:150px;"> 
    <div class="grs-multi-select-box "> 
    <input id="ssrBox" class="ssremployeeid" type="checkbox" name="ssremployeeid[]" 
    value="1312"> 
     Amanda Becker 
    </div> 
    <div class="grs-multi-select-box "> // same as above I just collapsed it for viewing purposes 
    <div class="grs-multi-select-box "> 
    <div class="grs-multi-select-box "> 
</div> //closes main div 

我不是爲複選框所獲得的價值,並沒有被選中。我做錯了什麼?

+3

<<所有checkboxed與頁面上相同的ID >> ID必須是上下文頁上是唯一的。對於作爲選擇醜陋的編碼使用:'$(「:複選框[ID = ssrBox]」)' –

+0

@roasted我希望所有的複選框是相同的值,但?我有點失落 – Squirtle

+3

一個ID應該永遠是唯一的。改爲使用班級。 – Sumurai8

回答

0

我與你試圖執行什麼很困惑。 您點擊Div或複選框?

下可能會幫助 - 給一個班的所有複選框。

喜歡的東西

$('#yourCheckboxID').click(function(){ 
    var checkboxValue = $(this).val(); 
    $('.yourCheckboxClass').attr('value',checkboxValue); 
}); 

我可以幫助更多的,如果你能創建的jsfiddle一個小的演示。

+0

所以我有3個像按鈕一樣的div。一旦我點擊添加,我想獲得所有點擊的複選框值的值,並將其分配給所有複選框。 – Squirtle