0

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

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

7 Comments

didn't helped, it still doesn't update the gallery_menu_style field from the table, no matter which of those 2 radio buttons i ticked :(
Replace the $_POST variables with defined ones (like $post1 = 1; $post2 = 2) and see if the PHP is behaving correctly. If it's inputting data, then it must be a problem with your jQuery. Another little test you can do is to check your JavaScript: remove everything inside the .click(function(){}) and replace with $(this).remove(); If the radio button disappears when clicked, the jQuery is recognising the click event but not the AJAX call
i checked the console from firebug..the post tab showed this showGalleryMenuStyleFromEditPage=2 ..or when i selected the first radio buttn showGalleryMenuStyleFromEditPage=1
Remove the first if statement, it's unnecessary - you're already checking the values with the two additional statements. As I said, define some variables like ($post1 = 1; $post2 = 2) and call the PHP with the AJAX function. You're replacing the $_POST variables with your own defined ones just to see if it's the User() class that's screwing things up...
ok, first i did was, I removed the if statement in the jquery, and tried the $(this)remove() , the button dissappeared..so I returned back the ajax, still not working... i tried replacing the value of each radio button to a predefined variable ..didn't work
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.