[英]how can i send a value onclick on a image in javascript to get a value in to a text field
i want to get a value from database
coresponding to this image
onclick
. 我想从database
获取与此image
onclick
。 but this function is not working i can't define value in img tag then how can i send this value to my function. 但是此功能不起作用,我无法在img标签中定义值,那么我该如何将该值发送到我的函数。
please help. 请帮忙。
<script type="text/javascript">
function choose(x)
{
document.getElementById('color').value=x;
}
</script>
<img src="admin/upload/<?php echo $data['image'];?>" value="<?php echo $data['color'];?>"
width="25" height="25" onclick="choose(this.value);"/>
<script type="text/javascript">
function choose(x)
{
document.getElementById('color').value=x;
}
</script>
<img src="admin/upload/<?php echo $data['image'];?>" title="<?php echo $data['color'];?>" width="25" height="25" onclick="choose(this.title);"/>
Just change the attribute value
to title
and onclick="choose(this.title)"
只需将属性value
更改为title
然后onclick="choose(this.title)"
Try this: 尝试这个:
<img src="admin/upload/<?php echo $data['image'];?>"
width="25" height="25" onclick="choose('<?php echo $data['color'];?>');"/>
You must create a ajax function to get a value from database like this 您必须创建一个ajax函数来从数据库中获取一个值,像这样
function choose(x)
{
$.ajax({
'type': 'get',
'url': 'getDataValue.php',
'data': 'color='+x,
success: function(data){
document.getElementById('color').value=data;
},
error: function(data){
alert("Ajax error occured");
}
});
}
Using ajax function you may fetch data from a table in getDataValue.php file. 使用ajax函数,您可以从getDataValue.php文件中的表中获取数据。 In getDataValue.php file you must run a query that get result from database table. 在getDataValue.php文件中,您必须运行一个从数据库表获取结果的查询。
Thanks 谢谢
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.