Welcome Guest, Not a member yet? Register   Sign In
Trying to submit form with jQuery
#1

[eluser]Uplift[/eluser]
I'm trying to submit a form with jQuery, it's showing the success function but it's not updating the database. I'm quite new to jQuery so i may have slightly missed something or wrong syntax or something. Can anyone see ?

Code:
$('#submit').click(function() {
            
            var newstyle = $('input[name=choosetheme]:checked').val();
        
            $.ajax({
                url: 'http://www.website.net/ubuzz/theme/update',
                type: 'POST',
                data: "newstyle="+ newstyle,  
                success: function() {
                    $('div.success').fadeIn();
                }
            });
            return false;
        });

// Theme controller

    function update() {    
        
        $data = $this->data_model->getSiteData();
        
        $userid = $data['userid'];
        
        $newstyle = $this->input->post('choosetheme'); // grab data from radio box
        
        $data = array('styleid' => $newstyle); // inserting the value of $newstyle to 'styleid' cell

        $this->forumdb->where('userid', $userid);
        $this->forumdb->update('user', $data);
    
    }

input[name=choosetheme]:checked

should return the checked radio box within the choosetheme name?

any suggestions
#2

[eluser]Twisted1919[/eluser]
Code:
$('form#FORM-ID-HERE').submit(function() {
            $.ajax({
                url: $(this).attr('action'),
                type: 'POST',
                data: $(this).serialize(),  
                success: function() {
                    $('div.success').fadeIn();
                }
            });
            return false;
        });
#3

[eluser]jblack199[/eluser]
OOh twisted that one helped me even (not that I was going to post about it, research is my friend)... been looking out how to use the form.serialize stuff -- i personally used it in the prototype.js many times but not jquery yet -- so you just knocked 2 birds with one stone by showing that code... kudos Big Grin
#4

[eluser]Uplift[/eluser]
thank you, much better




Theme © iAndrew 2016 - Forum software by © MyBB