TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 06-18-2009, 04:26 AM   #1 (permalink)
The Contributor
 
Join Date: May 2008
Posts: 36
Thanks: 5
Kay1021 is on a distinguished road
Default 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
Kay1021 is offline  
Reply With Quote
Old 06-18-2009, 11:23 AM   #2 (permalink)
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
Wildhoney is on a distinguished road
Default

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();
}
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote
Old 06-18-2009, 05:05 PM   #3 (permalink)
The Contributor
 
Join Date: May 2008
Posts: 36
Thanks: 5
Kay1021 is on a distinguished road
Confused

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
Kay1021 is offline  
Reply With Quote
Old 06-18-2009, 05:08 PM   #4 (permalink)
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
Wildhoney is on a distinguished road
Default

Doesn't my solution work for you?
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote
Old 06-18-2009, 05:12 PM   #5 (permalink)
The Contributor
 
Join Date: May 2008
Posts: 36
Thanks: 5
Kay1021 is on a distinguished road
Default

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
Kay1021 is offline  
Reply With Quote
Old 12-01-2009, 01:44 AM   #6 (permalink)
The Visitor
 
Join Date: Dec 2009
Posts: 1
Thanks: 0
bellsonracing is on a distinguished road
Default 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'));
}

});
});
bellsonracing is offline  
Reply With Quote
Old 06-03-2010, 05:01 AM   #7 (permalink)
The Wanderer
 
Join Date: Mar 2010
Posts: 8
Thanks: 0
infonama is on a distinguished road
Default

try using jquery, that will surely work.
__________________
Latest News
Download Free Songs
infonama is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Timezone Class: Dealing with Timezones the Proper Way Wildhoney General 2 01-10-2011 11:01 PM
php time? DizzyD General 20 06-10-2009 10:11 PM
Two Different Ways to Format the Time CMellor Tips & Tricks 0 09-24-2007 11:12 PM
Script Execution Time Class Wildhoney Script Giveaway 2 09-14-2007 11:36 PM
Calculating the Execution Time Wildhoney Tips & Tricks 0 09-14-2007 11:14 PM


All times are GMT. The time now is 06:08 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design