2014-01-14 25 views
0

我有文本框和下拉,我的問題是我有供應商和國家兩個下拉,但其採取供應商下降價值其唯一的國家下降。正在顯示來自數據庫下拉數據).ANY一個告訴我,我在哪裏出了錯如何通過阿賈克斯下拉值

HTML:

<form name="welcomeDiv1" id="welcomeDiv1"> 

<select name="supplier" id="supplier" style="margin:122px 0 0 939px;background-color:#E8E8E8;width:100px;position: absolute;"> 
    <option value="">Select supplier</option> 
<?php 

$sqlsupplier=mysql_query("SELECT supplier_id FROM supplier"); 


while($row=mysql_fetch_assoc($sqlsupplier)) 

{ 

    echo "<option value='" . $row['supplier_id'] . "'>" . $row['supplier_id'] . "</option>"; 
} 

    ?> 


</select> 


    <select id="country" name="country" style="margin:122px 0 0 511px;background-color:#E8E8E8;width:100px;position: absolute;" > 
     <option value="">Select Country</option> 
     <?php 

      $query = "SELECT DISTINCT country FROM globalnetwork"; 
      $result = mysql_query($query); 
      while($row = mysql_fetch_array($result)){ 
       echo "<option value='" . $row['country'] . "'>" . $row['country'] . "</option>"; 
      } 

     ?> 
    </select> 

</form> 

    <img src="/image/add-new.png" style="margin:116px 0 -5px 2659px;cursor:pointer;position: absolute;" class="billingadddet_button" > 

的JavaScript

$(function() { 
    $(".billingadddet_button").click(function() { 

    var CPH_GridView1_billingmonthid = $("#CPH_GridView1_billingmonthid").val(); 
    var CPH_GridView1_clientid = $("#CPH_GridView1_clientid").val(); 
    var CPH_GridView1_clientname= $("#CPH_GridView1_clientname").val(); 
    var CPH_GridView1_billingyear= $("#CPH_GridView1_billingyear").val(); 
    var CPH_GridView1_billingmonth = $("#CPH_GridView1_billingmonth").val(); 
    var CPH_GridView1_country = $("#country").val(); 
    var CPH_GridView1_supplier = $("#supplier").val(); 

    var dataString = 'CPH_GridView1_billingmonthid='+ CPH_GridView1_billingmonthid +'&CPH_GridView1_clientid='+CPH_GridView1_clientid+'&CPH_GridView1_clientname='+CPH_GridView1_clientname+'&CPH_GridView1_billingyear='+CPH_GridView1_billingyear+'&CPH_GridView1_billingmonth='+CPH_GridView1_billingmonth+'&CPH_GridView1_country='+CPH_GridView1_country+'&CPH_GridView1_supplier='+CPH_GridView1_supplier; 


    if(CPH_GridView1_clientid=='') 
    { 
    alert("Please Enter Some Text"); 
    } 
    else 
    { 
    $("#flash").show(); 
    $("#flash").fadeIn(400).html; 

    $.ajax({ 
    type: "POST", 
    url: "insertdetailed.php", 
    data: dataString, 
    cache: false, 
    success: function(html){ 
    $("#display").after(html); 

    window.location = '?action=billingdatainputandexportdetailedreport'; 
    $("#flash").hide(); 
    } 
    }); 
    } return false; 
    }); 
    }); 

insertdetailed.php

$billingmonthid = $_POST['CPH_GridView1_billingmonthid']; 
if(isSet($_POST['CPH_GridView1_billingmonthid'])) 

{ 
$billingmonthid = $_POST['CPH_GridView1_billingmonthid']; 
$clientid=$_POST['CPH_GridView1_clientid']; 
$clientname=$_POST['CPH_GridView1_clientname']; 
$billingyear=$_POST['CPH_GridView1_billingyear']; 
$billingmonth=$_POST['CPH_GridView1_billingmonth']; 
$country=$_POST['CPH_GridView1_country']; 
$supplier=$_POST['CPH_GridView1_supplier']; 

$sql_insert="insert into billingdetailedreport(billingmonthid,clientid,clientname,billingyear,billingmonth,supplier,country) values ('$billingmonthid','$clientid','$clientname','$billingyear','$billingmonth','$supplier','$country')"; 
//print "Here"; 
print $sql_insert; 
mysql_query($sql_insert); 

} 

回答

1

試試這個

$("#country option:selected").val(); 

同爲Suplier

$("#supplier option:selected").val(); 

此外,我可以建議使用$( 「#welcomeDiv1」).serialize()並在阿賈克斯請求中使用它

Hop這將有助於。