mootools radio button problem
I am a newbie to mootools and web development also. 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. 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
<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_f开发者_如何学Pythonull.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
<?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 :
click: function(value) {
// Send ajax request to server ...
}
instead of 'click', the name of the CallBack function is onClick i.e.
onClick: function(value) {
// Send ajax request to server ...
}
about the 'click', you could do this way i.e.
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/
精彩评论