2013-04-10 209 views
1

我在一個PHP項目的工作,禁用和啓用onclick事件不工作的多行

好,我需要幫助像我有10條記錄的數據更新到數據庫中看到如下─診斷

enter image description here

現在喜歡你看到No_Info選項,說:No_Data和Available。

所以,當用戶點擊ID爲1的No_data時,它會禁用附加到相應ID的字段。 和相同的可用作品。

但它只是所有工作的ID:1,不爲別的,排它的工作.....

編輯:這裏更新的代碼。

>>>> <?php 
//connect to the database server 
$objConnect = mysql_connect("localhost","root","") or die(mysql_error()); 
//select the database 
$objDB = mysql_select_db("main_project"); 
//select which data you want to get. 
$sql   = "SELECT * FROM website_maindb"; 
$objQuery  = mysql_query($sql); 
// $Ct = mysql_query('select * from company_type'); 
/* $objResult  = mysql_fetch_array($objQuery); // Not to use when using loop to call full database */ 
?> 
    <!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"> 
    <head> 
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> 
    <title>ss</title> 
    <script> 
function disable() 
{ 
document.getElementById("noi1").disabled=true; 
document.getElementById("noi2").disabled=true; 
document.getElementById("noi3").disabled=true; 
document.getElementById("noi4").disabled=true; 
document.getElementById("noi5").disabled=true; 
document.getElementById("noi6").disabled=true; 

} 
function enable() 
{ 
document.getElementById("noi1").disabled=false; 
document.getElementById("noi2").disabled=false; 
document.getElementById("noi3").disabled=false; 
document.getElementById("noi4").disabled=false; 
document.getElementById("noi5").disabled=false; 
document.getElementById("noi6").disabled=false; 
} 
</script> 
    </head> 
    <body> 

<form id="form" action="insert.php" method="post"> 
<table width="700" border="1"> 
<tr> 
<th></th> 
<th width="20"> <div align="center">ID </div></th> 
<th width="98"> <div align="center">website </div></th> 
<th width="98"> <div align="center">category </div></th> 
<th width="98"> <div align="center">email </div></th> 
<th width="98"> <div align="center">contact form </div></th> 
<th width="98"> <div align="center">Primary No. </div></th> 
<th width="98"> <div align="center">Secondary No. </div></th> 
<th width="98"> <div align="center">fax </div></th> 
<th width="98"> <div align="center">Company type </div></th> 
<th width="98"> <div align="center">No_Info </div></th> 
<th width="98"> <div align="center">time </div></th> 
</th> 
</tr> 
<?php 
$options = ''; 
$Ctype=mysql_query("select distinct typec from company_type"); 
while($row = mysql_fetch_array($Ctype)) { 
    $options .="<option>" . $row['typec'] . "</option>"; 
} 
?> 

<?php 
$i = 0; 
while($objResult = mysql_fetch_array($objQuery)) 
{ 
$i++; 
?> 
<tr> 
<td><input type="hidden" name="WID" value="<?=$objResult["WID"];?>"></td> 
<td><label><input type="text" name="ID" value="<?=$objResult["WID"];?>" disabled></label></td> 
<td><input type="text" name="website" value="<?=$objResult["website"];?>"></td> 
<td><input type="text" name="cat" size="10"></td> 
<td><input type="text" id="noi1" name="email" size="10"></td> 
<td><input type="text" id="noi2" name="cform" size="10"></td> 
<td><input type="text" id="noi3" name="contactp" size="10"></td> 
<td><input type="text" id="noi4" name="contacts" size="10"></td> 
<td><input type="text" id="noi5" name="fax" size="10"></td> 
<td><select id="Ctype" name="Ctype"> <?=" $options "?> </select></td> 
<td><button type="button" onclick="disable()" size="20">No_Data</button> </br> 
<button type="button" onclick="enable()" size="20">Available</button> 
</td> 
<td><input type="text" id="noi6" name="time" size="10"></td> 
</tr> 
<?php 
} 
?> 
<button type="submit" id="send">Submit</button> 
</form> 
</table> 
</body> 
</html> 

誰能幫助解決它..

+0

您可能想要在問題中添加代碼,因爲要在pastebin中查看您需要一個帳戶,並且我懷疑是否每個人都有一個pastebin帳戶。 – Daanvn 2013-04-10 07:11:51

+3

這是一個私人粘貼。 – 2013-04-10 07:11:51

+3

1.您通常會在此粘貼相關代碼,因爲pastebin coudl會在某天終止,如果存在,您將無法重新讀取此問題。 2.你的pastebin是私人的! – ITroubs 2013-04-10 07:12:05

回答

1

你正在做它稍有不妥。您必須在數組中構建表單字段。像這樣:

<input type="text" id="noi1_<?php echo $i; ?>" name="email[]" size="10">

和你的按鈕是這樣的:

<button type="button" onclick="disable('<?php echo $i; ?>')" size="20">No_Data</button>

然後,在你的JS:

function disable(idx) 
{ 
    document.getElementById("noi1_"+idx).disabled=true; 
    . 
    . 

。 。

然後最後當你收到$ _POST的表單時,你會得到$ _POST ['email']作爲一個數組。

+1

非常感謝!這工作順利:) – devilcrab 2013-04-10 09:31:08

+1

非常歡迎:D – 2013-04-10 09:33:20

+0

還有一個問題,就像我的應用程序頁面顯示數據庫中的數據例如。 7條記錄是可用的然後當我更新所有領域,如你看到圖像中的表單,它應該更新數據庫中的所有字段,但它只更新數據庫中的最後一行不是全部。如果在下拉菜單中有多個選擇,它會再次出現問題,比如我們在第1行中選擇了1個類別,第7行中選擇了第1個類別,那麼它將同時顯示第7行中用逗號分隔的類別選擇,並將其存儲在數據庫中。爲什麼這樣 ? – devilcrab 2013-04-10 09:33:43

0
**Please Share the Enable code...** 


$(document).ready(function() { 

$("#submit").click(function() { 
var name = $("#name").val(); 
var cname = $("#cname").val(); 
var email = $("#email").val(); 
var contact = $("#contact").val(); 
var msg = $("#msg").val(); 
if (name == '' || cname == ''|| email == '' || contact == '' || msg == '') { 
alert("Insertion Failed Some Fields are Blank....!!"); 
} else { 
// Returns successful data submission message when the entered information is stored in database. 

$.post("re.php", { 
name1: name, 
cname1: cname, 
email1: email, 
contact1: contact, 
msg1: msg 
}, function(data) { 
alert(data); 
//$('#form')[0].reset(); // To reset form fields 

}); 

} 

}); 
function NextButton() {   

mySubmitButton = document.getElementById("submit");   

mySubmitButton.click(); 

myOpenButton = document.getElementById("form1");  

myOpenButton.click();  

} 
$("#submit").click(function(){ 

    $("#name").prop("disabled",true); 
    $("#cname").prop("disabled",true); 
    $("#email").prop("disabled",true); 
    $("#contact").prop("disabled",true); 
    $("#msg").prop("disabled",true); 
}); 


$("#submit1").click(function() { 
var name3 = $("#name3").val(); 
var cname3 = $("#cname3").val(); 
var email3 = $("#email3").val(); 
var contact3 = $("#contact3").val(); 
var msg3 = $("#msg3").val(); 
if (name3 == '' || cname3 == ''|| email3 == '' || contact3 == '' || msg3 == '') { 
alert("Insertion Failed Some Fields are Blank....!!"); 
} else { 
// Returns successful data submission message when the entered information is stored in database. 

$.post("re.php", { 
name4: name3, 
cname4: cname3, 
email4: email3, 
contact4: contact3, 
msg4: msg3 
}, function(data) { 
alert(data); 
//$('#form')[0].reset(); // To reset form fields 

}); 
} 
}); 
$("#submit1").click(function(){ 

    $("#name3").prop("disabled",true); 
    $("#cname3").prop("disabled",true); 
    $("#email3").prop("disabled",true); 
    $("#contact3").prop("disabled",true); 
    $("#msg3").prop("disabled",true); 
}); 
}); 

This code for a disable value coding please share the value enable coding 
+0

添加一些描述,而不是僅轉儲代碼。 – 2017-08-19 05:07:49