I have two radio buttons
<div align="center" class="radio_group">
<input type="radio" id="gallerymenustyle1" class="element radio" name="gallerymenustyle[]" value="1" /> Gallery Link - In the navigation of my website, display one "gallery" link<br />
<input type="radio" id="gallerymenustyle2" class="element radio" name="gallerymenustyle[]" value="2" /> Category Links - In the navigation of my website, display a separate link to each category.
</div>
how to update one field from a row, once I clicked one of those radio buttons without hitting a submit button ?
here'开发者_开发百科s what i have so far
$(function(){
$(':radio').click(function(){
if($(this).is(':checked'))
{
var galleryMenuStyleVal = $(this).val();
$.ajax({
type: 'POST',
url: '<?php echo BASE_URL; ?>ajax/ajax_methods_gallery.php',
data: 'showGalleryMenuStyleFromEditPage=' + galleryMenuStyleVal
});
}
});
});
if($_POST['showGalleryMenuStyleFromEditPage'] !== null || $_POST['shoGalleryMenuStyleFromEditPage'] !== 0){
$userObj = new User();
if($_POST['showGalleryMenuStyleFromEditPage'] == 1){
$query = "UPDATE users SET gallery_menu_style = 1";
$userObj->updateUserGalleryMenuStyle($query);
} else if ($_POST['showGalleryMenuStyleFromEditPage'] == 2){
$query = "UPDATE users SET gallery_menu_style = 2";
$userObj->updateUserGalleryMenuStyle($query);
}
}
is my jquery correct including some portions of PHP ? ..because it's not working
On this line:
if($_POST['showGalleryMenuStyleFromEditPage'] !== null || $_POST['shoGalleryMenuStyleFromEditPage'] !== 0){
You used 'shoGalleryMenuStyleFromEditPage' instead of 'showGalleryMenuStyleFromEditPage' on the second $_POST value. It's therefore not allowing anything to get through that initial if statement.
You've also used !== 0
instead of != 0
.
This is why using short keys/names isn't such a bad idea...
If it's still not working, use Firebug to ascertain whether your jQuery's actually sending anything.
精彩评论