douhuo0884 2014-03-16 20:11
浏览 75
已采纳

在具有类检查的div中的jquery目标输入值

I am foreaching a number of suppliers in a quotation form, each with a checkbox element to tick which should be contacted. suppliers are in divs with class names supplier-checkbox, moreover upon selecting supplier the supplier-checkbox div gets appended with "checkedsupplier" or "uncheckedsupplier" class name.

<div class="supplier-checkbox checkedsupplier">

<input type="hidden" name="supplier-email" class="supplieremail" value="{$item->email}" />
                                    </div> <!--end supplier checkbox-->

foreach supplier div I get a hidden input field within the div holding the supplier email as its value. idea is that upon submitting form I'd check for all div's with "checkedsupplier" class name and for each obtain the value of the input inside of it, hold all values in onelong variable and echo it into the To field of the email to replicate the quotation form to each supplier.

using jquery, I managed to toggle the class name and a background effect showing ticked or unticked with the below.

<script> 
    $(".supplier-checkbox").click(function(){
    $(this).toggleClass('checkedsupplier uncheckedsupplier')
    //$(this).children( ".supplieremail" ).attr("checked")
});
</script>

can anyone give me any pointers on how to foreach by class name and fetch value of each input inside every div with that class name using jquery. Im working on it and yet found the .each for looping .val for values and if (bar) for conditional. but am not yet experienced enough to put things together. have been working as a junior developer for 7 months now since graduating in networking which is a completely different field.

in the app.js file I'm obtaining the form values this way: `

v_country:$('#country').val(),
v_quotationtel:$('#quotationtel').val(),
                v_mobile:$('#mobile').val(),
                v_quotationemail:$('#quotationemail').val(),
                v_quotemefor:$('#quotemefor').val(),
    v_quotemessage:$('#quotemessage').val()
                //this line is what i'm trying to do to get input values and store them in one var to pass them to php form that sends email $( "checksupplier" ).each(function( i ) {

         }`

thanks everyone on stack! I believe in you guys here you've all helped me throughout my studies and work.

Ian

** Update ** It's been modified to work as follows:

 <script>
        $(function(){
            $( ".crew-member-con" ).click(function(){
                $(this).toggleClass('whitebg greybg');
                $(this).toggleClass('crew-checked crew-unchecked');
                $(this).toggleClass('grey white');
                if($(this).children('input').prop('checked') == true){
                    $(this).children('input').prop('checked', false);
                }else{
                    $(this).children('input').prop('checked', true);
                }

                var selectedMembers='';
                $('.selected-members').each(function(){
                    if($(this).is(':checked')){
                        selectedMembers +=$(this).val()+', ';
                    }
                   //alert(emails);
                });
                if(selectedMembers != ''){
                    selectedMembers = selectedMembers.slice(0,-2);
                }
                $('#exam-member span').html(selectedMembers);
                console.log(selectedMembers);
});         

        });
  • 写回答

2条回答 默认 最新

  • duanpie4763 2014-03-16 20:21
    关注
    <script> 
    $(".supplier-checkbox").click(function(){
    $(this).toggleClass('checkedsupplier uncheckedsupplier')
    //$(this).children( ".supplieremail" ).attr("checked")
    var emails='';
    $('.supplieremail').each(function(){
       emails +=$(this).val();
    });
    
    $('#mailfieldstextarea').val(emails);
    });
    </script>
    

    I hope this will help.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 个人网站被恶意大量访问,怎么办
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大