Scriptaculous onclick ( on select ?) event from menu dropdown

An unforeseen issue with the behaviour I did not spot.

Using Option 1, and press Order (the hidden div contains a select menu) then the first value of this hidden select menu gets sent to Reflector

Array
(
    [List1] => Option 1
    [message] => Array
        (
            [0] => -8.00
        )

)

I need to exclude these values if “prescription” is “not” selected

Demo here:

http://www.printlineadvertising.co.uk/demo/menuselect/getting-nearer.html

David

On 1 Jul 2010, at 17:13, Walter Lee Davis wrote:

See if changing Submit to submit in the observer function has any effect on the problem. Just this line:

$(document.forms[0]).observe(‘submit’,strip_hidden);

It seemed to help here.

Walter

On Jul 1, 2010, at 12:02 PM, David Owen wrote:

OK got that, and moved the second part inside the first no errors.

(BTW I’m NOT using the Protaculous Action in this instance, I’m using code direct in the “before ” section on Freeway)

getting-nearer

the form sends to Reflector

But this still showing the hidden field data sent by the form

Array
(
 [List1] => Option 1
 [message_title] => Array
     (
         [0] => Prescription Code:
     )

 [message] => Array
     (
         [0] =>
     )

)

David

On 1 Jul 2010, at 16:15, Walter Lee Davis wrote:

This error means that the page does not have a form on it. Which shouldn’t be possible. But it might be explained thus: At the moment that the script runs, the code that describes the form object has not been downloaded to the browser.

You need to do one of two things. The easiest would be to move the entire script, starting with function strip_hidden… and ending before the end-script tag, inside the document.observe block. This Pastie shows before and after, and I admit the difference appears subtle: http://pastie.org/1026711

What this does is place all of your code inside another “listener” function, which waits until the document has entirely downloaded to the browser (but usually before the page has become visible) and then fires off your code. It guarantees that everything is ready for the code, but doesn’t require that you break your JavaScript across multiple blocks placed throughout the page. And in most cases, it readies the effect before anything is visible on the page. This keeps you from having the “flash of scripted content”, where you see something for a fraction of a second and then it disappears as the page is set up for some visual effect.

You can get the same effect by using the Protaculous Action to place the code on the page. If you click on either of the Function Body buttons in Protaculous, you will get a code editing window where you can place a lump of code. The top button wraps your code inside the ‘dom:loaded’ listener function, which means (sorry for shouting) YOU HAVE TO REMOVE THAT from your code. If you were to remove the first line and the last line from my corrected script, and paste that inside the top Function Body dialog in Protaculous, you would end up with the same code.

The second button is for a different event: Event.observe(window,‘load’,function(evt){ your code here }); The reason you might want to use this versus the other has to do with timing. On a large page, you might have tons of photos or other resources that take a while to download. You want your script to do something visual with the page, but you want it to wait until everything is visible to start. So then you would use the second button and put your code there.

Walter

On Jul 1, 2010, at 9:34 AM, David Owen wrote:

I’m getting an error :frowning:

TypeError: Result of expression '$(document.forms[0])' [undefined] is not an object.

find menu and disable field

Google is not really helping me with this probably because I understand what “//to apply it, set a listener on the form’s submit event:” means but not entirely sure where/how to implement it.

David

On 1 Jul 2010, at 09:36, David Owen wrote:

0 Jun 2010, at 17:24, Walter Lee Davis wrote:

This script will fix that.

function strip_hidden(evt){
evt.stop();
	var f = $(this);
	f.getElements().each(function(elm){
		if(!elm.visible() ||
			elm.ancestors().find(
				function(m){
					return ! m.visible();
				})
			){
			elm.remove();
		}
	});
	f.submit();
}
//to apply it, set a listener on the form's submit event:
$(document.forms[0]).observe('submit',strip_hidden);

dynamo mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options


dynamo mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options


dynamo mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options


dynamo mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options


dynamo mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Try this version of the strip_hidden function:

http://www.pastie.org/1073006

I have no idea why it’s behaving this way, but this version uses long-hand DOM methods rather than the Prototype remove() function to remove the form elements that have hidden parents, and it seems to work with your form.

Walter


dynamo mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Me neither, thanks that works now.

David

On 3 Aug 2010, at 15:32, waltd wrote:

I have no idea why it’s behaving this way


dynamo mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Here’s the finished job if you want a look: http://www.ledglasses.co.uk/

David

On 3 Aug 2010, at 15:32, waltd wrote:

Try this version of the strip_hidden function:

http://www.pastie.org/1073006

I have no idea why it’s behaving this way, but this version uses long-hand DOM methods rather than the Prototype remove() function to remove the form elements that have hidden parents, and it seems to work with your form.

Walter


dynamo mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options


dynamo mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

That’s really excellent! One suggestion: put your prescription form element inline, above the Order button, so it pushes the Order button down when it’s needed. On my 15" laptop, the magical appearing form was appearing below the fold, so I didn’t see it there.

Walter


dynamo mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Hi David,
A really great looking site (even without my Speculite’s on!). :slight_smile:
Although maybe not a huge market your client should maybe market these
to DJs, nightclub security staff etc. They remind me of watching
Orbital in my youth who would wear these while DJing;
http://technomusicnews.com/images/OrbitalWithGlasses.jpg
All the best,
Tim.

On 3 Aug 2010, at 18:07, David Owen wrote:

Here’s the finished job if you want a look: http://www.ledglasses.co.uk/

FreewayActions.com - Freeware and commercial actions for Freeway
Express & Pro.

Protect your mailto links from being harvested by spambots with Anti
Spam.
Only available at FreewayActions.com

http://www.freewayactions.com


dynamo mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Good idea, I tend to be spoiled using a large iMac screen.

It’s all run with WebYeb, the client maintains his pricing, postage, descriptions, product shots. It’s quite a flexible CMS for small sites, or small shops.

David

On 3 Aug 2010, at 19:10, “waltd” email@hidden wrote:

That’s really excellent! One suggestion: put your prescription form element inline, above the Order button, so it pushes the Order button down when it’s needed. On my 15" laptop, the magical appearing form was appearing below the fold, so I didn’t see it there.

Walter


dynamo mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options


dynamo mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

I could do with a pair of these - any chance of a discount?

David


dynamo mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Is that singular or plural? (discounts can be coded:) )

Afraid that’s something you’ll have to ask the client.

David

On 3 Aug 2010, at 20:02, “DeltaDave” email@hidden wrote:

I could do with a pair of these - any chance of a discount?

David


dynamo mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options


dynamo mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options