我需要将'id'字段返回给服务器,而不是'name'字段。 无论我尝试什么,当我改变'name'字段但我不能得到'id'的'name'。当我更改“姓名”字段时,ID未被更改...
这是我的代码: 的索引
<?php
include "koneksi.php";
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="en-US" xml:lang="en">
<head>
<link rel="shortcut icon" href="images/favicon.ico" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
<title>Sms Gateway By Nightwalker Team</title>
<link rel="stylesheet" href="development-bundle/themes/base/jquery.ui.all.css">
<script src="development-bundle/jquery-1.6.2.js"></script>
<script src="development-bundle/ui/jquery.ui.core.js"></script>
<script src="development-bundle/ui/jquery.ui.widget.js"></script>
<script src="development-bundle/ui/jquery.ui.button.js"></script>
<script type="text/javascript" src="js/jquery_notification_v.1.js"></script>
<script type="text/javascript" src="js/jquery.watermark.min.js"></script>
<link href="css/jquery_notification.css" type="text/css" rel="stylesheet"/>
<link href="paging.css" rel="stylesheet" type="text/css">
<script type="text/javascript" src="script.js"></script>
<link rel="stylesheet" href="style.css" type="text/css" media="screen" />
<!--[if IE 6]><link rel="stylesheet" href="style.ie6.css" type="text/css" media="screen" /><![endif]-->
<!--[if IE 7]><link rel="stylesheet" href="style.ie7.css" type="text/css" media="screen" /><![endif]-->
<style>
body { font-size: 62.5%; }
label, input { display:block; }
input.text { margin-bottom:12px; width:95%; padding: .4em; font-size:12px; }
fieldset { padding:0; border:0; margin-top:25px; }
textarea {margin-bottom:12px; width:90%; padding: .4em; font-size:12px;}
div#users-contain table { margin: 1em 0; border-collapse: collapse; width: 100%; }
div#users-contain table td, div#users-contain table th { border: 1px solid #eee; padding: .6em 10px; text-align: left; }
.style1 {font-size: 18px}
</style>
<script>
$(document).ready(function(){
$( "#tambah" )
.button()
.click(function() {
var Name = $ ("#Name").val();
var Number = $ ("#Number").val();
var GroupID = $("#GroupID :selected").val();
//kirim ke proses_group.php
$.ajax({
type:"POST",
url:"proses_tambah_group.php",
//pisahkah dengan tanda & jika mengirim lebih dari 1 data
data: "Name=" + Name + "&Number=" + Number + "&GroupID=" + GroupID,
success: function(data){
$("#groupinfo").html(data);
}
});
});
});
</script>
</head>
<body>
<form>
<fieldset>
<label for="Name">Nama</label>
<input type="text" Name="nama" id="Name" class="text ui-widget-content ui-corner-all" />
<label for="email">Nomor</label>
<input type="text" Name="nomor" id="Number" class="text ui-widget-content ui-corner-all" />
<?php
echo"<select id='GroupID' >";
include "koneksi.php";
$sql = mysql_query("select * from pbk_groups");
while ($data = mysql_fetch_array($sql)){
echo"<option Value='$data[ID]'>$data[Name]</option>";}
echo"</select>";
?>
</fieldset>
</form>
<br>
<button id="tambah">Tambah</button>
<p> </p>
<div id="groupinfo"></div>
</body>
<html>
这个过程
<?php
include "koneksi.php";
$Name = $_POST['Name'];
$Number = $_POST['Number'];
$GroupID = $_POST['GroupID'];
$input = mysql_query("insert into pbk(Name,Number,GroupID)
values ('$Name','$Number','$GroupID')");
//Jika proses berhasil
if ($input){
?>
<script type="text/javascript">
showNotification({
message: "<?php echo "Pesan Dikirim"; ?>",
type: "success",
autoClose: true,
duration: 2
});
</script>
<?php
}
else {
?>
<script type="text/javascript">
showNotification({
message: "<?php echo "Pesan Gagal" ?>",
type: "error",
autoClose: true,
duration: 2
});
</script>
<?php
}
?>
答案 0 :(得分:0)
如果我理解正确,您希望表单在用户输入名称时找到相应的ID?
表单中有两个不同的“名称”:text
输入和select
。
您的选择是否正确填充了您的PHP代码? 检查你的html输出。
您是否在select
中选择了该名称?
如果没有,您将缺少根据名称查找ID的代码:
change-the-selected-value-of-a-drop-down-list-with-jquery