开发者

Textbox problem with onclick @

I'm just trying to display a table in client side from database as a distinct value from every column. Here i have fetched the value by using "select distinct ...." code and put this value in a single textbox

here is the code...

   <!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" st开发者_如何学Cyle="visibility:hidden" /> </td>
        </label>
    </form>
    </td>
  </tr>
</table>

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


EDIT:

The following is a sample where the value of the textbox is displayed in an alert box. As the others have said, cannot suggest anything other than this without seeing code.

Example

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


First don't call your function onclick better name is something like LanguageClick.

Second, don't give same id to all elements.. if you don't have real use for it just omit the ID it won't break anything.

Third, proper event is onfocus as user can reach the textbox by pressing Tab key, which won't trigger the click event.

Code would look like this:

<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);" />

And the JavaScript code:

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

As you pass this to the function, you have reference to the textbox element and you can read its value property.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜