Anyone any good with onChange events?
Posted: 25 June 2009 05:18 AM   [ Ignore ]  
Professor
Avatar
RankRankRankRankRankRankRank
Total Posts:  10835
Joined  04-15-2006

Hiya,

Was just wondering if anyone is any good with onChange events in forms and can help me figure out why this won’t work in certain Browsers?

It works fine in Safari (OSX) and some versions of Firefox (OSX) but not all and I’m not sure what IE does as I don’t have access to it at the moment.

Was just wondering if I’m doing something blatantly wrong of if there is a better way of going about this?

My code so far is this :

<form id="drop" action="#">
<
select id="down" size="1">

Under that then I have a weblog entries tag which is used to output the different options. As mentioned above in Safari it all works fine, the page refreshes and goes to the correct URL but in certain versions of Firefox (read as most versions - not too sure where I was when it did work on Firefox) it won’t work. Also I’m not sure if this works in Firefox on Windows or IE on windows.

I’m just wondering if there’s a better way of doing these things perhaps?

Thanks for any help on this.

Best wishes,

Mark

 Signature 

Shopping Cart Plugin
Full list of add-ons
———————————————————-
Buy me a drink, or two if you like!!

Profile
 
 
Posted: 25 June 2009 09:33 AM   [ Ignore ]   [ # 1 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  2062
Joined  09-16-2004

Mark, care to point us to an actual page? Are you using a JS framework? (jQuery, Mootools…)

 Signature 

Peace, e-man.
stookstudio.com, websites built with care and web standards. LinkedIn profile

Profile
 
 
Posted: 25 June 2009 09:56 AM   [ Ignore ]   [ # 2 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1215
Joined  12-18-2008

as far as radio boxes and checkboxes go, you should use the click event instead of change (IE doesn’t fire the change event until the radio button/checkbox has lost focus).  that said, I’ve never encountered a problem using change for select boxes, although perhaps it’s a similar problem where IE still thinks the dropdown has focus and won’t fire til it loses focus.

other than that… yeah need a link to a demo of the problem

 Signature 

EE Pro Network
eMarketSouth - web design & development, SEO, video production, and more
ExpressionEngine consulting services - complex SQL queries, .htaccess url rewriting, custom plugins/modules/extensions, template optimization, javascript/jQuery enhancements, and more!
Skype: tywangsness

Profile
 
 
Posted: 25 June 2009 10:25 AM   [ Ignore ]   [ # 3 ]  
Professor
Avatar
RankRankRankRankRankRankRank
Total Posts:  10835
Joined  04-15-2006

Hi both,

Unfortunately I can’t provide a link as the data which is being shown on the page is highly confidential. I shall hopefully make one on my own (not built yet wink ) site tonight and provide a link to that instead.

As mentioned before it all works fine in Safari but not Firefox. This is OSX by the way.

Also if it helps at all no JS frameworks at all although I’m not against doing that if I have to and as a pointer I used the code from the Category Dropdown Menu in the ExpressionEngine documentation if that helps at all?

Will hopefully get a page up tonight though.

Best wishes,

Mark

 Signature 

Shopping Cart Plugin
Full list of add-ons
———————————————————-
Buy me a drink, or two if you like!!

Profile
 
 
Posted: 25 June 2009 12:25 PM   [ Ignore ]   [ # 4 ]  
Professor
Avatar
RankRankRankRankRankRankRank
Total Posts:  10835
Joined  04-15-2006

Okay here we go, a page to test with.

Drop Down Test

If it works for you then you will get redirected to a page which asks for a username and password which is needed as this is sensitive data but will demonstrate if the actual drop-down redirect works or not though.

Other than the fact that my form isn’t 100% valid code due to not having fieldsets (I seriously hope that’s not it now I’ve said that wink ) then I can’t really see much else that it could be.

An extra pair of eyes on this would be great so thanks for any help on it.

Best wishes,

Mark

 Signature 

Shopping Cart Plugin
Full list of add-ons
———————————————————-
Buy me a drink, or two if you like!!

Profile
 
 
Posted: 25 June 2009 01:58 PM   [ Ignore ]   [ # 5 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1215
Joined  12-18-2008

yeah I’d use jQuery for that, just easier to attach the events once since they’re all roughly the same.

something like:

$(document).ready(function() {
    
$("#drop select").change(function(e) {
        [removed]
= $(this).val();
    
});
});

I assume that the point of these dropdowns is to send you to a new page.. if not then the above code won’t be quite right wink

edit: [removed] = window dot location

 Signature 

EE Pro Network
eMarketSouth - web design & development, SEO, video production, and more
ExpressionEngine consulting services - complex SQL queries, .htaccess url rewriting, custom plugins/modules/extensions, template optimization, javascript/jQuery enhancements, and more!
Skype: tywangsness

Profile
 
 
Posted: 25 June 2009 02:02 PM   [ Ignore ]   [ # 6 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  2062
Joined  09-16-2004

Mark, on that test page you are loading jQuery so I did a little test using it.

I removed the inline event handler:

<form id="drop" action="#">
<
select id="down" size="1">
<
option value="#">Choose a pilot…</option>

and moved event handling over to a jQuery snippet:

$(document).ready(function(){
        
$('#down').change(function() {
            location
.href = this.options[this.selectedIndex].value;
            return
false;
        
});
        
    
});

(obviously surrounded by script tags but you know the forum strips these out).
I did a test run with the dropdowns: 1 dropdown using jQuery, the other 2 using inline event handlers. Only the jQuery dropdown worked in Safari, FF on Mac OS X and FF and IE7 on WinXP.
Hope this helps!

 Signature 

Peace, e-man.
stookstudio.com, websites built with care and web standards. LinkedIn profile

Profile
 
 
Posted: 25 June 2009 03:01 PM   [ Ignore ]   [ # 7 ]  
Professor
Avatar
RankRankRankRankRankRankRank
Total Posts:  10835
Joined  04-15-2006

e-man / ender,

Thank you thank you!! grin

All seems to be working fine. Will do some testing but that’s great, thanks.

One last thing I was wondering though as I have three drop-downs on that page and my Javascript knowledge is absolute pants I was wondering if there would be an easy way to make that function work for all three differently named drop-downs instead of just the one instead of me copying the function two more times and changing the names in them?

If not then no problem will just do that instead but thought I would ask nevertheless.

Thanks again for the help on this one.

Best wishes,

Mark

 Signature 

Shopping Cart Plugin
Full list of add-ons
———————————————————-
Buy me a drink, or two if you like!!

Profile
 
 
Posted: 25 June 2009 03:12 PM   [ Ignore ]   [ # 8 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1215
Joined  12-18-2008

my code should do that already wink

$("#drop select").change

means for each select element that is a child of the element with ID=drop, do stuff.

since all three select boxes were children of #drop it will run that function for any of the three that are changed.

 Signature 

EE Pro Network
eMarketSouth - web design & development, SEO, video production, and more
ExpressionEngine consulting services - complex SQL queries, .htaccess url rewriting, custom plugins/modules/extensions, template optimization, javascript/jQuery enhancements, and more!
Skype: tywangsness

Profile
 
 
Posted: 28 June 2009 10:55 AM   [ Ignore ]   [ # 9 ]  
Professor
Avatar
RankRankRankRankRankRankRank
Total Posts:  10835
Joined  04-15-2006

Hiya,

ender - 25 June 2009 03:12 PM

my code should do that already wink

$("#drop select").change

means for each select element that is a child of the element with ID=drop, do stuff.

since all three select boxes were children of #drop it will run that function for any of the three that are changed.

Sorry for not coming back sooner on this one although to tell the truth I could have sworn I did already post back to this but seems that I didn’t so sorry about that.

Thanks again both for the code. Got it working in the end with I think it was a mix of the two so thank you both for all the help.

Would still love to hear if anyone knows why the original code was mucking up in certain browsers though?

Best wishes,

Mark

 Signature 

Shopping Cart Plugin
Full list of add-ons
———————————————————-
Buy me a drink, or two if you like!!

Profile
 
 
Posted: 29 June 2009 08:03 AM   [ Ignore ]   [ # 10 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1215
Joined  12-18-2008

jQuery has sorta spoiled us all on the browser compatibility front. so the answer you’re likely to get to that question is that you weren’t using jQuery to do it. wink

I honestly used to know a bunch of browser incompatibilities when it came to javascript, but jQuery’s goal is to be the same in all the browsers it supports… so I don’t have to remember which things work in which browsers anymore.

 Signature 

EE Pro Network
eMarketSouth - web design & development, SEO, video production, and more
ExpressionEngine consulting services - complex SQL queries, .htaccess url rewriting, custom plugins/modules/extensions, template optimization, javascript/jQuery enhancements, and more!
Skype: tywangsness

Profile
 
 
Posted: 29 June 2009 10:24 AM   [ Ignore ]   [ # 11 ]  
Professor
Avatar
RankRankRankRankRankRankRank
Total Posts:  10835
Joined  04-15-2006

Yep I suppose the old adage of “If It Ain’t broke, don’t fix it” comes to mind here. I’ll just live with the fact that it is working and I suppose not get too worried about why the other one didn’t.

It’s just that most of the time I like to know what has happened so that it’s in my mind in case it ever happens again so that I can fix it quickly. Now I’m running with both your new versions though I suppose I can just forget this one and get on with life though grin

Thanks again both for all your help.

Best wishes,

Mark

 Signature 

Shopping Cart Plugin
Full list of add-ons
———————————————————-
Buy me a drink, or two if you like!!

Profile
 
 
   
 
 
Post Marker Legend
New Topic New posts Hot Topic Hot Topic with new posts New Poll New Poll Moved Topic Moved Topic Sticky Topic Sticky topic
Old Topic No new posts Hot Old Topic Hot Topic with no new posts Old Poll Old Poll Closed Topic Closed Topic Announcement Announcements
Theme
Change Theme
Visitor Statistics
The most visitors ever was 1743, on December 02, 2009 03:47 PM
Total Registered Members: 120626 Total Logged-in Users: 121
Total Topics: 126656 Total Anonymous Users: 58
Total Replies: 665795 Total Guests: 505
Total Posts: 792451    
Members ( View Memberlist )
Active Members:    3000adlurAlexis Moore-JonesAlistair StubbsALWCAndrea DeMersAndy HarrisAt the GatesbenbennittbiberltdbudparrBurly ChassischaasClareCraig AllenCrucialDan HalbertDaniel DeckerdaveJayderDerek JonesdesignerhandbagsDJ NAMdubsakdward10Dylan Smith/ContextDesigneeartemarketsouthepdmylerErik ReaganForrest AndersonFrank Harrisongcuevasghd_GnuusgomacroGuy StephensheaversmHrimthursIan EbdenimpdesignsinfoinfoITWYjackwatkinsJacob RussellJarrett BarnettJörg GudehusJeremy Lee JamesjoemoJohn GielenJohn Mortonjulie pkaeptnkcdunstanKemper Technology ConsutlingKevin EvansLisa EliverpoolrclukeadamisLWTmaleikaMandaraxMarc TiedemannMark BowenmarramgrassMatt HarrisMatthew EllisMattJeansmdesignMichael ByströmMilo CreativemrscareyNallasivanNevin LynenoddyokayyellowPaalesParisJCpasquale7duffyPaul StonePDMpeachoramapixeldeluxe_arnoldpMacedpushloopqbrandsramonekalsawregistryRichard WigginsrippeRobb OttenhoffrobeehedRobert Eerhartroi.agnetaRonnyrunning with scissorsRyan J. Bonnells0uthpawsakanaSean McDevittSimon CoxsmartpillstphnmartinSue CrockerSupercoolTambour BattanttiltbuilttisquisTodd Stravis creadyvobtoaviWaielweb@sewaneewondermade