2011-02-02 80 views
1

我只是試圖在數據庫中顯示客戶端的一個表格,作爲每列中不同的值。onclick的文本框問題@

的:在這裏,我以「選擇不同的......」代碼和一個文本框

這裏是代碼把這個值...

<!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=utf-8" /> 
    <title>Untitled Document</title> 


<script type="text/javascript"> 
function onClick() 
{ 
    alert(document.form.thirdparty.value); 

    } 
</script> 




</head> 

<body> 
<p>&nbsp;</p> 
<form name="form" method="get" > 

<?php 
$con=mysql_connect('localhost','root',''); 
mysql_select_db('database',$con); 
$res = mysql_query("SELECT count(*) as count FROM tablename") or die(mysql_error()); 
while ($row = mysql_fetch_array($res)) { 
$val=$row['count']; 

} ?> 


<input name="fino" type="text" id="fino" size="5" value="<?php echo $val." docs" ?>" style="border-style:hidden; color:#0083fa;" /> 


<table width="1474" height="270" border="0" > 
    <tr> 
    <td width="180" height="41"> 




      <input name="Item" type="DocumentType" id="textfield5" value="     Item"size="30" /> </td> 
    <td width="180" height="41"> 


     <label> 
    <td width="180" height="41"> <input type="text" name="textfield8" id="textfield8" style="visibility:hidden" /></td> 
     </label> 


     <label> 
     <td width="180" height="41"> <input type="text" name="textfield9" id="textfield9" style="visibility:hidden"/></td> 
     </label> 





    </td> 
    </tr> 
    <tr> 
    <td> 

<?php 
$a=mysql_query("select distinct language from tablename"); 
$c=0; 
$i=1; 
$x=1; 
while($row = mysql_fetch_array($a)) 
{ 
$b=$row['language']; 
$i=$b; 
$d=mysql_query("select count(*) as count from tablename where language='$i' "); 
while ($row = mysql_fetch_array($d)) { 
$e=$row['count']; 
$cal=round(($e/$val)*100); 


} 
?> 


//in this textbox am using onclick function 

     <input type="text" size="30" style="height:<?php echo $cal.px?>"value="<?php echo "$i"."&nbsp;"."&nbsp;"."&nbsp;"."$e"." docs" ?>"name="language" id="textfield"onClick="onClick();" /> 

     <?php 
$i++; 
$c++; 
} 
?> </td> 
<td> 
<?php 
$con=mysql_connect('localhost','root',''); 
mysql_select_db('database',$con); 
$a1=mysql_query("select distinct Subject from tablename"); 
$c1=0; 
$i1=1; 
while($row = mysql_fetch_array($a1)) 
{ 
$b1=$row['Subject']; 
$i1=$b1; 
$d1=mysql_query("select count(*) as count from tablename where Subject='$i1' "); 
while ($row = mysql_fetch_array($d1)) { 
$e1=$row['count']; 
$cal1=round(($e1/$val)*100); 
} 
?> 



     <input type="text" size="30" style="height:<?php echo $cal1.px?>" value="<?php echo "$i1"."&nbsp;"."&nbsp;"."&nbsp;"."$e1"." docs" ?>"name="item" id="textfield2" /> 
<?php 
$i++; 
$c++; 
} 
?> </td> 
    <td> 


     <label> 
     <td> <input type="text" name="textfield12" id="textfield12" style="visibility:hidden" /></td> 
     </label> 

     <label> 
     <td> <input type="text" name="textfield13" id="textfield13" style="visibility:hidden" /></td> 
     </label> 

     <label> 
     <td> <input type="text" name="textfield14" id="textfield14" style="visibility:hidden" /></td> 
     </label> 


     <label> 
     <td> <input type="text" name="textfield15" id="textfield15" style="visibility:hidden" /> </td> 
     </label> 
    </form> 
    </td> 
    </tr> 
</table> 

    <blockquote> 
    <p align="center">&nbsp;</p> 
</blockquote> 
</body> 
</html> 
+4

如果您希望我們修復您的代碼,您必須向我們提供您的代碼。在這裏粘貼你的JavaScript。 – 2011-02-02 07:47:31

+0

這是一個JavaScript問題。您正嘗試訪問不存在的對象。你可以發佈一些代碼,這樣人們可以幫助你更好嗎? – 2011-02-02 07:49:30

+0

爲什麼還原到rivision 1? – Nanne 2011-02-02 09:51:01

回答

1

編輯獲取的價值以下是一個示例,其中文本框的值顯示在警告框中。正如其他人所說的,除非看到代碼,否則不能提出任何其他建議。

<input type = 'text' id = 'myTextBox' onclick='alert(this.value)' /> 
0

先不要打電話給你的函數onclick更好的名字是一樣的東西LanguageClick

其次,不要給所有元素同樣的id ..如果你沒有真正的使用它,只需省略ID就不會破壞任何東西。

三,正確的事件是onfocus,因爲用戶可以通過按Tab鍵來觸及文本框,這將不會觸發點擊事件。

代碼應該是這樣的:

<input type="text" size="30" style="height:<?php echo $cal.px?>;" value="<?php echo "$i"."&nbsp;"."&nbsp;"."&nbsp;"."$e"." docs" ?>" name="language" onfocus="LanguageClick(this);" /> 

和JavaScript代碼:

function LanguageClick(oTextbox) { 
    var sValue = oTextbox.value; 
    alert("You wrote: " + sValue); 
} 

。當你穿過this的功能,你必須參考文本元素,你可以閱讀其value屬性。