jQuery没有从下拉列表中获取选定的值 [英] Jquery not getting the selected value from dropdown

查看:45
本文介绍了jQuery没有从下拉列表中获取选定的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试获取选定下拉列表的值,该选定值存储在数据库中,但下面没有采用选定值,这是我的代码可以指导如何做到这一点.谢谢

I am trying to get the value of selected drop down,the selected value to store in database but it not takeing the selected value below is my code can one guide how to do it.thanks

已更新

clientnetworkpricelist/update.php

$dbHost = 'localhost'; // usually localhost
$dbUsername = 'xxx';
$dbPassword = 'xxxxxxxx';
$dbDatabase = 'fms';
$db = mysql_connect($dbHost, $dbUsername, $dbPassword) or die ("Unable to connect to Database Server.");
mysql_select_db ($dbDatabase, $db) or die ("Could not select database.");

$client_id=$_POST['clientid'];
    $feild=$_POST['field'];
            $data= $_POST['value'];
            $rownum=$_POST['rowid'];  
            $sql="UPDATE $client_id SET ".$feild." = '".$data."' WHERE net_id = ".$rownum."";

             print $sql;



            mysql_query($sql)

;  

HTML

<?php
$client_id=$_GET['clientid'];

if($client_id!=""){

$sql=mysql_query("select * from supplierprice a JOIN $client_id b WHERE b.`net_id` = a.`supp_price_id`" );
$query = "SELECT route FROM routestable WHERE `clientid` = '$client_id' ";
$result = mysql_query($query);
//print "query". $query;

while($rows=mysql_fetch_array($sql))
{

if($alt == 1)
        {
           echo '<tr class="alt">';
           $alt = 0;
        }
        else
        {
           echo '<tr>';
           $alt = 1;
        }

echo '   <td  class=" '.$rows["net_id"].'">'.$rows["clientid"].'</td>
         <td id="CPH_GridView1_clientid" class=" '.$rows["net_id"].'">'.$rows["region"].'</td>  
        <td id="CPH_GridView1_country" class=" '.$rows["net_id"].'">'.$rows["country"].'</td>
        <td id="CPH_GridView1_networkname" class=" '.$rows["net_id"].'">'.$rows["networkname"].'</td>
        <td id="CPH_GridView1_mcc"  class=" '.$rows["net_id"].'">'.$rows["mcc"].'</td>   
        <td id="CPH_GridView1_mnc"  class="'.$rows["net_id"].'">'.$rows["mnc"].'</td>
        <td id="CPH_GridView1_mnp" class="edit mnp '.$rows["net_id"].'">'.$rows["mnp"].'</td>';
  /*                        
         $ColumnNames = mysql_query("SELECT column_name FROM information_schema.COLUMNS WHERE table_name = 'supplierprice' AND column_name NOT
IN ('supp_price_id','net_id','region', 'country', 'networkname', 'mcc', 'mnc', 'mnp'
)") or die("mysql error"); 

$columnArray=array();*/


foreach($columnArray as $value) {


//$columnArray[]=$rows1[0];

echo '<td  id="CPH_GridView1_xxx" width="0px;" class="edit '.$value.' '.$rows["net_id"].'">'.$rows[$value].'</td>';   
}   



 echo ' <td id="CPH_GridView1_clientprice" class="edit clientprice '.$rows["net_id"].'">'.$rows["clientprice"].'</td>
        <td> <select name="mySelect" id="mySelect" class="edit route '.$rows["net_id"].'" >';         



           // $query = "SELECT route FROM routestable WHERE `clientid` = '$client_id' `"; 
           // print "Query is".$query; 
            $result = mysql_query($query);
            while ($rows = mysql_fetch_assoc($result))  
            {  
                echo '<option value="' . $rows['route'] . '"> ' . $rows['route'] .     '</option>';  
               // echo '<option value="Hi"> Hi</option>';
            }   


         echo '</select>
                            </td>

                <td></td>'


        ;

echo '</tr>';

}
}
?>

ajax

$(document).ready(function(){ 
    $('#mySelect').on('change keyup', function(){
        arr = $(this).attr('class').split( " " );
        var clientid=document.getElementById("client").value;

        $.ajax({    type: "POST",
            url:"clientnetworkpricelist/update.php",
           data: "value="+$('#mySelect').find(":selected").val()+"&rowid="+arr[2]+"&field="+arr[1]+"&clientid="+clientid,
            success: function(data){
            $('.ajax').html($('.ajax input').val());
            $('.ajax').removeClass('ajax');
        }});
    });


    $('#editbox').live('blur',function(){
        $('.ajax').html($('.ajax input').val());
        $('.ajax').removeClass('ajax');
    });
});

推荐答案

$('.ajax input').val()是这里的问题,请确保您在您的HTML.

$('.ajax input').val() is an issue here, please make sure you have an input element in your HTML.

如果要在帖子中使用 mySelect 值,

If want to use mySelect value in post,

data: "value="+$(this).val()+"&rowid="+arr[2]+"&field="+arr[1]+"&clientid="+clientid,

还有这里

$('.ajax').html($('.ajax input').val());

在这种情况下,您需要使用 edit 类选择器.ID是唯一属性,这就是原因,它适用于第一个元素.

In that case, you need to use edit class selector. ID is unique attribute, thats the reason, it was worked for first one element.

             $('.edit').on('keyup change', function(){              

                  arr = $(this).attr('class').split( " " );

                  var clientid=document.getElementById("client").value;

                    $.ajax({    type: "POST",
                        url:"clientnetworkpricelist/update.php",
                        data: "value="+$(this).val()+"&rowid="+arr[2]+"&field="+arr[1]+"&clientid="+clientid,
                        success: function(data){
                        $('.ajax').html($('.ajax input').val());
                        $('.ajax').removeClass('ajax');
                    }});
                });

这篇关于jQuery没有从下拉列表中获取选定的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆