[英]mootools radio button problem
I am a newbie to mootools and web development also. 我也是mootools和网络开发的新手。 I have read this pretty cool blog and I want to extend the code to connect with a database to update the rating with a php file.
我已经阅读了这个非常酷的博客 ,我想扩展代码以与数据库连接以使用php文件更新评级。 but unfortunately my code not working means database is not updating.
但是不幸的是我的代码无法正常工作,这意味着数据库没有更新。 Can someone please explain me why.
有人可以解释一下为什么吗。 Thanks a lot...
非常感谢...
Here's the code 这是代码
star.html star.html
<html>
<script src="mootools-1.3.js"></script>
<script src="lorenzos-MooStarRating-422072a/Source/moostarrating.js"></script>
<script>
// Configure the image paths
var MooStarRatingImages = {
defaultImageFolder: 'lorenzos-MooStarRating-422072a/Graphics/',
defaultImageEmpty: 'star_empty.png',
defaultImageFull: 'star_full.png',
defaultImageHover: "star_boxed_hover.png"
};
// Post iD
var postId = 10;
// When the DOM is ready....
window.addEvent("domready",function() {
// Create our instance
// Advanced options
var advancedRating = new MooStarRating({
form: 'ratingsForm',
radios: 'rating',
half: false,
//imageEmpty: 'star_boxed_empty.png',
//imageFull: 'star_boxed_full.png',
//imageHover: "star_boxed_hover.png",
width: 17,
tip: 'Rate <i>[VALUE] / 7.0</i>',
tipTarget: $('htmlTip'),
tipTargetType: 'html',
click: function(value) {
// Send ajax request to server
new Request.send({
url: "rateSave.php",
data: {'rating': value}
});
}
});
});
</script>
<form name="ratingsForm">
<label>Select The Number of Stars</label>
<input type="radio" name="rating" value="1.0" checked="checked">
<input type="radio" name="rating" value="2.0">
<input type="radio" name="rating" value="3.0">
<input type="radio" name="rating" value="4.0">
<input type="radio" name="rating" value="5.0">
<input type="radio" name="rating" value="6.0">
<input type="radio" name="rating" value="7.0">
<!--<input type="radio" name="rating" value="7.5">
<input type="radio" name="rating" value="8.0">
<input type="radio" name="rating" value="8.5">
<input type="radio" name="rating" value="9.0">
<input type="radio" name="rating" value="9.5">
<input type="radio" name="rating" value="10.0">-->
<span id="htmlTip"></span>
</form>
</html>
rateSave.php rateSave.php
<?php
$con = mysql_connect("localhost","root","");
if (!$con){
die('Could not connect: ' . mysql_error());
}
mysql_select_db("rating", $con);
$starCount =$_POST['rating'];
$result=mysql_query("INSERT INTO star VALUES('hotel','$starCount')");
mysql_close($con);
?>
Hi Pavithra Gunasekara, the error is 'nothing', here : 嗨,Pavithra Gunasekara,错误为“ nothing”,在这里:
click: function(value) {
// Send ajax request to server ...
}
instead of 'click', the name of the CallBack function is onClick ie CallBack函数的名称是onClick而不是“ click”,即
onClick: function(value) {
// Send ajax request to server ...
}
about the 'click', you could do this way ie 关于“点击”,您可以这样做
advancedRating.addEvent('click', function(){ new Request.send({/* ... */}) });
working example with 'onClick' instead of the 'click' inside the new instance definition: http://jsfiddle.net/steweb/LDw4y/ 新实例定义中使用“ onClick”而不是“ click”的示例: http : //jsfiddle.net/steweb/LDw4y/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.