简体   繁体   English

来自选择框和复选框的数据

[英]Data from selectbox and checkbox

I want to get data from my select/dropdown box and from my checkboxes. 我想从我的选择/下拉框和复选框中获取数据。 I get the data from the input fields like this: 我从这样的输入字段中获取数据:

 'formData'         : {
   'timestamp' : '<?php echo $timestamp;?>',
   'token'     : '<?php echo md5('unique_salt' . $timestamp);?>',
   'parentId'      : $('input[name=parentId]').val(),
   'projectnr'      : $('input[name=projectnr]').val(),
   'gebruiker'      : $('input[name=gebruiker]').val(),
   'gebruikerid'      : $('input[name=userId]').val(),
   'uploadbash'      : '<?php echo $uploadbash; ?>'
 },

How do I get the selected value from my <select> field and checkboxes? 如何从<select>字段和复选框中获取选定的值?

I tried: 我试过了:

  'groepId'      : document.getElementsByName("map")

But it doesn't work... 但这行不通...


The select looks like this: 选择看起来像这样:

<select name="map" id="map">
                                <option value="0">Algemeen</option>
                <?php
                    if(mysql_num_rows($query_select_map) != 0)  {

                        while($fetch_map = mysql_fetch_assoc($query_select_map))    {
                            if($fetch_map['parent'] != "")  {
                                $voegtoe = ">";
                            }
                            echo '<option value="'.$fetch_map['id'].'">'.$voegtoe.' '.$fetch_map['naam'].'</option>';
                        }
                    }
                    ?>
                            </select>

Weird thing, i build in this check: 奇怪的是,我建立了这张支票:

<script type="text/javascript">
$(document).ready(function(){
$('#zenden').click(function(){
alert($('#map').val());
});
});
</script>

When I submit I get the right number of the selected item in my alert box, but it sends the wrong number the next page. 当我提交时,我在警报框中得到了正确的所选项目编号,但它在下一页发送了错误的编号。 All other data is right... 所有其他数据都是正确的...

怎么样:

$("input[name=map]:checked").val();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM