TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   Javascript, AJAX, E4X (http://www.talkphp.com/javascript-ajax-e4x/)
-   -   onSelect/onDeselect working at same time? (http://www.talkphp.com/javascript-ajax-e4x/4569-onselect-ondeselect-working-same-time.html)

Kay1021 06-18-2009 04:26 AM

onSelect/onDeselect working at same time?
 
I'm kinda a newbie to Javascript but i have seemed to figure out one part of what i am trying to do and need help with the second part. What i am trying to do is this checkbox that has a style from here http://lipidity.com/fancy-form/. But what i wanted was that once you click select or deselect the checkbox that it is automatically updated to the database. I was already doing something like this with a textarea and i finally figured out how to get it to work with my checkbox. I used part of the help the site gave..
Code:

FancyForm.start( 0, {
        onSelect: function(chk){
                alert(chk.inputElement.getProperty('name'));
        }
});


and rearranged it and used some of my other code and got it to actually work for what i need. My code:
Code:

FancyForm.start(0, {
                onSelect: function(chk) {               
                        var url = 'schoolPage.php?catID=' + chk.inputElement.getProperty('id') + '&chk=' + chk.inputElement.getProperty('checked');
                                var request = new Request({
                                        url:url,
                                        method:'POST',
                                        onRequest: function() {
                                                alert('making sure it works:: ' + url);
                                        }
                                }).send();
                       
                       
                }
               
        });

so that works ....and if change it to onDeselect it works....when you uncheck a box....however i some how need them both in there....and so when you select or deselect the box that it will send the info. Being new to javascript I just can figure out the prop

Wildhoney 06-18-2009 11:23 AM

Something like the following would work for you:

javascript Code:
FancyForm.start(0, {
        onSelect: makeAjaxCall(chk),
        onDeselect: makeAjaxCall(chk)
    });
   
function makeAjaxCall(chk)
{
    var url = 'schoolPage.php?catID=' + chk.inputElement.getProperty('id') + '&chk=' + chk.inputElement.getProperty('checked');
        var request = new Request({
            url:url,
            method:'POST',
            onRequest: function() {
                alert('making sure it works:: ' + url);
            }
        }).send();
}

Kay1021 06-18-2009 05:05 PM

Thanks I was really hoping that was going to work. Unfortunately for some reason when i put that code of if i put

Code:

FancyForm.start(0, {
                onSelect: function(chk) {               
                        var url = 'schoolPage.php?catID=' + chk.inputElement.getProperty('id') + '&chk=' + chk.inputElement.getProperty('checked');
                                var request = new Request({
                                        url:url,
                                        method:'POST',
                                        onRequest: function() {
                                                alert('making ajax call :: ' + url);
                                        }
                                }).send();
                       
                       
                }
               
                onDeselect: function(chk) {               
                        var url = 'schoolPage.php?catID=' + chk.inputElement.getProperty('id') + '&chk=' + chk.inputElement.getProperty('checked');
                                var request = new Request({
                                        url:url,
                                        method:'POST',
                                        onRequest: function() {
                                                alert('making ajax call :: ' + url);
                                        }
                                }).send();
                       
                       
                }
               
        });

then it gets rid of the styles which is the whole point of using the fancy form checkbox. Plus it doesn't do anything anyways...no alert pops up like its suppose to. That's why i thought maybe i was writing it wrong....or there was another way to do it. I'm not sure why it's acting this way....seems like i can only have select or deselect when i need both.

thanks for your help

Wildhoney 06-18-2009 05:08 PM

Doesn't my solution work for you?

Kay1021 06-18-2009 05:12 PM

Sorry I meant to say your solution as well as the top code do the same thing....it eliminate the styles of the fancy form and then it doesn't even do anything when you select or deselect

bellsonracing 12-01-2009 01:44 AM

Got it to work
 
window.addEvent('domready', function(){
FancyForm.start( 0, {
onSelect: function(chk){
alert(chk.inputElement.getProperty('name'));
alert(chk.inputElement.getProperty('checked'));
},
onDeselect: function(chk){
alert(chk.inputElement.getProperty('name'));
alert(chk.inputElement.getProperty('checked'));
}

});
});

infonama 06-03-2010 05:01 AM

try using jquery, that will surely work.


All times are GMT. The time now is 12:58 PM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0