单击radio
按钮时,在其他字段中插入相应的数据
例如
+---------+-----------+------+
| Name | Phone No |tick |
+---------+-----------+------+
| AB | 67890 | o |
+---------+-----------+------+
| CD | 12345 | o |
+---------+-----------+------+
__________
phone |__________| (textbox/textarea)
当我点击单选按钮(假设我点击第一个)时,相应的电话号码(67890)应插入下面的文本框中。这些数据是从数据库加载的。
我在javascript中尝试了onclick
,但我猜不会在php中工作。
请帮忙
我的代码是
<?php
include("data.php");
echo"<table border='1'>";
$result=@mysql_query("SELECT *from t");
echo "<form>";
if(mysql_num_rows($result)>0)
{
echo"<tr align='left'>";
echo"<th><font color='black'>name";
echo"<th><font color='black'>phone";
echo"<th><font color='black'>Tick";
echo "</tr></thead>";
$a=0;
while($test = mysql_fetch_array($result))
{
$a=$a+1;
echo "<tbody>";
echo"<td><input type='text' name='phone[$a]' value=$test[ph]></td>";
echo"<td>".$test['name']."</td>";
echo"<td><input type='checkbox' name='tick' onclick='fill(this.form,$a)'></td>";
echo "</tr></tbody>";
}
echo"</table>";
echo"<td></br><input type='text' name='sec_phone'></td>";
echo "</form>";
mysql_close($conn);
}
?>
<script type="text/javascript" language="JavaScript">
function fill(f,a) {
if(f.tick.checked == true) {
f.sec_phone.value = f.phone[a].value;
}
}
</script>
答案 0 :(得分:0)
这里我的代码希望它可以帮助你解决问题
<form action="">
<table width="200" border="1">
<tr>
<td>Name</td>
<td>Phone No</td>
<td>tick</td>
</tr>
<tr>
<td>AB</td>
<td><div id="phone_1">67890</div></td>
<td>
<input type="radio" name="phone" id="Check_1" >
</td>
</tr>
<tr>
<td>CD</td>
<td><div id="phone_2">12345</div></td>
<td>
<input type="radio" name="phone" id="Check_2" >
</td>
</tr>
</table>
</form>
<br>
<input type="text" value="">
$( "#Check_1" ).click(function() {
var text = $( "#phone_1" ).text();
$( "input" ).val( text );
});
$( "#Check_2" ).click(function() {
var text = $( "#phone_2" ).text();
$( "input" ).val( text );
});