如何使用firebug进行调试并显示单选按钮的值

时间:2013-04-17 09:42:46

标签: php javascript jquery firefox

我有单选按钮,如下所示。

        <div id="lensType">

                        <input type="radio"  name="design" style="vertical-align: middle"  value="1"/>
                        <label for="design">Single Vision</label><br/>

                        <input type="radio" name="design" style="vertical-align: middle" value="2" />
                        <label for="material" >Accommodative Support</label><br/>

                        <input type="radio"  name="design" style="vertical-align: middle"  value="3"/>
                        <label for="design">Bifocal</label> <br/>

                        <input type="radio"   name="design" style="vertical-align: middle" value="4" />
                        <label for="material" >Varifocal (Intermediate/Near)</label><br/>

                        <input type="radio"   name="design" style="vertical-align: middle" value="5"/>
                        <label for="material" >Varifocal (Distance/Near)</label>

                    </div>

我正在进行动态选择。我有我的javascript代码发布值。似乎供应商价值现已公布。下面是我的脚本的代码。

  $(document).ready(function(){

     function populate() {
      fetch.doPost('getSupplier.php');
   }

 $('#lensType').change(populate);

  var fetch = function() {

 var counties = $('#county');

return {
doPost: function(src) {

$('#loading_county_drop_down').show(); // Show the Loading...
$('#county_drop_down').hide(); // Hide the drop down
$('#no_county_drop_down').hide(); // Hide the "no counties" message (if it's the case)


    if (src) $.post(src, { supplier: $('#lensType').val() }, this.getSupplier);

    else throw new Error('No source was passed !');
},

getSupplier: function(results) {
    if (!results) return;
    counties.html(results);

$('#loading_county_drop_down').hide(); // Hide the Loading...
$('#county_drop_down').show(); // Show the drop down
}   
  }
 }();

 populate();

 });

Php代码:

<?php
  if(isSet($_POST['supplier'])) {

   include 'db.php';

  $stmt = $mysql->prepare("SELECT DISTINCT SupplierBrand FROM plastic WHERE          HeadingNo='".$_POST['supplier']."'");
  $stmt->execute();
  $stmt->bind_result($supplierBrand);

  while ($row = $stmt->fetch()) : ?>

 <option value="<?php echo $supplierBrand; ?>" width="100px"><?php echo $supplierBrand; ?></option>
 

我的问题是当我调试时我注意到没有传递给php脚本的值,这使得select为空。我试图通过让firebug输出console.log进行跟踪或调试,但在这方面失败了。 请协助使用此代码,该代码旨在通过单选按钮选择显示动态列表。

2 个答案:

答案 0 :(得分:2)

用于调试:

$('input[name="design"]').change(function(){ 
console.log($('#lensType').find("input:radio[name ='design']:checked").val());
});

否则:

$('#lensType').find("input:radio[name ='design']:checked").val();

而不是

$('#lensType').val()

并且你可能希望用改变的函数包装它,因为onload没有选择设计:

  $(document).ready(function(){
$('input[name="design"]').change(function(){ 
var design = $('input[name="design"]:checked').val();
     function populate() {
      fetch.doPost('getSupplier.php');
   }

 $('#lensType').change(populate);

  var fetch = function() {

 var counties = $('#county');

return {
doPost: function(src) {

$('#loading_county_drop_down').show(); // Show the Loading...
$('#county_drop_down').hide(); // Hide the drop down
$('#no_county_drop_down').hide(); // Hide the "no counties" message (if it's the case)


    if (src) $.post(src, { supplier: design }, this.getSupplier);

    else throw new Error('No source was passed !');
},

getSupplier: function(results) {
    if (!results) return;
    counties.html(results);

$('#loading_county_drop_down').hide(); // Hide the Loading...
$('#county_drop_down').show(); // Show the drop down
}   
  }
 }();

 populate();
});
 });

答案 1 :(得分:1)

在你的javascript中,你得到div的值,而不是单选按钮:

$('#lensType').val() <--- change that

对于这样的事情:

$("#lensType input:radio[name='design']:checked").val()