Scriptaculous onclick ( on select ?) event from menu dropdown

Got that.

I knew this would expand in complexity, the final project is part of a form going to a Mals shopping cart, there are certain (hidden) form values that have to be published into the ‘redbox’ ~ but only when ‘redbox’ visible. Otherwise these hidden value get passed to the mals cart together with blank customer data as part of the page form and is printed in the message fields at mals.

To make this complete I need to create a series of variables (20 in total) to then publish the redbox with these values included. The rest of the form is ignored if ‘redbox’ is hidden.

I could do this with php and re-load the whole page (slower) without the slide effect, but maybe this could all be wrapped up in javascript in one hit?

http://www.printlineadvertising.co.uk/demo/menuselect/option.html

I’m declaring variables at the top of the script. Can the switcheroo function change the cartvalue1 etc variables? Not sure if it can when written outside the function.

<script type="text/javascript">//<![CDATA[

var cartvalue1; cartvalue ="this extra code is published only when box is shown and not if hidden";
var cartvalue2; cartvalue ="something else";

document.observe('dom:loaded', function(){
  $('redbox').hide();
  var switcheroo = function(){
    if($F('List1') == 'Option 3' || $F('List1') == 'Option 2'){
      new Effect.SlideDown('redbox', {duration: .5, delay :0} );

cartvalue1 ="changedvalue";
cartvalue2 ="changedvalue";

    }else{
      if($('redbox').visible()){
        new Effect.SlideUp('redbox' , {duration: .5, delay:0} ); 
      }
    }
  }
  $('List1').observe('change',switcheroo);
});
//]]></script>

David

On 29 Jun 2010, at 19:52, Walter Lee Davis wrote:

If you are switching the same box in and out, and you want it to respond to the picker being on 2 OR 3, then you would simply modify the test line:

if($F(‘List1’) == ‘Option 3’ || $F(‘List1’) == ‘Option 2’){

On US keyboards, the “pipe” character is on the same keycap as the backslash. Two pipes in a row mean “or” in most programming languages. So in between ‘Option 3’ and $F('List1 above are two pipes, not two lower-case Ls or two upper case Is.

Walter

On Jun 29, 2010, at 2:22 PM, David Owen wrote:

One last thing, a second item needs putting in the menu to drive the same effect on the same box for example ‘option 2’

would this fight the action being performed when selecting ‘option 2’ directly after selecting ‘option 3’ if not could it be done?

Select list

$('redbox').hide();
var switcheroo = function(){
	if($F('List1') == 'Option 3'){
		new Effect.SlideDown('redbox');
	}else{
		if($('redbox').visible()){
			new Effect.SlideUp('redbox');
		}
	}
}
$('List1').observe('change',switcheroo);

On 28 Jun 2010, at 19:33, Walter Lee Davis wrote:

That’s because you’ve given the SELECT (picking list) and the DIV that holds it on the page the same ID (List1). No two things on a page can have the same ID. Since the DIV comes first in the source code of your page, Prototype is trying to get the Form.Element#GetValue function to run against it. But since a DIV is not a form element, the function fails.

Click on the left-most tab in the Inspector while this form element is selected in Freeway. Change the Title field to something besides List1. Then click on the right-most tab and confirm that the Name field still reads List1. Your Extended ID should not be affected by this change.

Walter

On Jun 28, 2010, at 1:45 PM, David Owen wrote:

Walt,

The updated Freeway page is balking with an error :-

TypeError: Result of expression 'Form.Element.Serializers[method]' [undefined] is not a function.

Select list

David

On 28 Jun 2010, at 16:24, waltd wrote:

And if the picker changes from Option 3 back to something else, it should slide back up, right?

Here’s one way to do this.

$('redbox').hide();
var switcheroo = function(){
	if($F('List1') == 'Option 3'){
		new Effect.SlideDown('redbox');
	}else{
		if($('redbox').visible()){
			new Effect.SlideUp('redbox');
		}
	}
}
$('List1').observe('change',switcheroo);

Some things to note about this. First, you have to change the Library picker in Protaculous from prototype (or prototype-packed) to scriptaculous-packed for this to work. Second, your picking list as you have drawn it has a DIV surrounding it that has the ID ‘mylist’, but the picker itself does not have an ID. In order to use Prototype to get the value out of a picker, that picker has to have an ID. Once it does, then the value of a picker can be gotten using:

$(‘theIdOfThePicker’).getValue();

or the shorter and preferred version:

$F(‘theIdOfThePicker’);

To add an ID to a picker in Freeway, you can use the FormFix Action, or you can use Item / Extended when the picker is selected, then make sure you choose the tab in the Extended dialog before clicking New, entering id as the Name and theIdOfThePicker as the Value. (Naturally, changing that to something unique and meaningful to you.) I added an ID to the picker while testing this. It’s a good idea to have any form element’s name and ID match exactly, simply because IE has kittens if they don’t.

Here’s a link to the working page:

http://jsbin.com/unafo

Oh, and one other gotcha waiting to pounce: your DIV that you slide into view cannot be empty. That’s a bug in Scriptaculous 1.8, maybe it’s fixed in the next version, but I haven’t checked. Freeway works around this when you use the Transition FX Action by inserting an empty DIV in any element that’s animated using these effects. But I imagine that your real page would never go to all this trouble to animate an empty box into view, so this is just a warning if you’re following along with a similar trivial test document.

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


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

Certainly this can be done. The individual hidden fields would need to
have IDs added to them for this to work. I don’t believe that the Form
Setup dialog lets you do that, though, so you should experiment with
my FormFix Action in Page mode to see if that cleans up that problem
for you.

The syntax to put inside your switcheroo would be this:

 $('theIdOfTheHiddenField').setValue('123.45');

But I think that overall, you might want to re-think how this whole
thing works. It might be simpler within Freeway to create each set of
options in its own “redbox”, stack them all on top of each other, and
then only show the one that is pertinent to the choice in the picking
list. There’s another thread on this list or maybe the main
FreewayTalk list from last week where I helped someone build exactly
that form for a Mals cart.

One thing that will definitely help you here is that any form element
that is hidden with JavaScript (not hidden in the sense of ) will not be submitted to the server. So if you had a lot
of form elements, but most of them had their display property set to
none through JavaScript (which is what happens when you apply the
Prototype function hide() to them) then they would be missing from the
form submission. So only the elements that you’ve enabled through your
picker will go anywhere.

Walter

On Jun 30, 2010, at 9:58 AM, David Owen wrote:

cartvalue1 =“changedvalue”;
cartvalue2 =“changedvalue”;


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

Sorry I sould have been a little more specific I’m sending a hidden field value alongside each text field for example “my value” to accompany the use text field value.

If the user leaves these value as blank, these hidden fields “are” still being sent when the ‘redbox’ is hidden by the script and Mals then displays these unless I can disable them to “” nothing

This bits are inserted as code.

<input type="hidden" name="message_title[]" value="my value">
<input type="text" name="message[]" size="5">

so do I document.write the variables like I would use php to echo / print

Or I suppose the simplest is to use the existing script to simply hide() ?

David

On 30 Jun 2010, at 15:13, Walter Lee Davis wrote:

Certainly this can be done. The individual hidden fields would need to have IDs added to them for this to work. I don’t believe that the Form Setup dialog lets you do that, though, so you should experiment with my FormFix Action in Page mode to see if that cleans up that problem for you.

The syntax to put inside your switcheroo would be this:

$(‘theIdOfTheHiddenField’).setValue(‘123.45’);

But I think that overall, you might want to re-think how this whole thing works. It might be simpler within Freeway to create each set of options in its own “redbox”, stack them all on top of each other, and then only show the one that is pertinent to the choice in the picking list. There’s another thread on this list or maybe the main FreewayTalk list from last week where I helped someone build exactly that form for a Mals cart.

One thing that will definitely help you here is that any form element that is hidden with JavaScript (not hidden in the sense of ) will not be submitted to the server. So if you had a lot of form elements, but most of them had their display property set to none through JavaScript (which is what happens when you apply the Prototype function hide() to them) then they would be missing from the form submission. So only the elements that you’ve enabled through your picker will go anywhere.

Walter

On Jun 30, 2010, at 9:58 AM, David Owen wrote:

cartvalue1 =“changedvalue”;
cartvalue2 =“changedvalue”;


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

You can’t use document.write within an anonymous function. Anything
you write with the Protaculous Action gets wrapped in an anonymous
function to keep it from “leaking” into the global namespace.

So the options would be to use Element.setValue to set the value to
nothing or Element.hide to make it disappear altogether.

On balance, I’d go with hide, because there’s no telling what might
happen in a Freeway document if you had two fields with the same name,
and one of them is blank and the other has a value set by the customer.

I say in Freeway because it’s never all that clear what order these
elements will end up in the source code. And the last one “wins”,
usually, when submitting forms. So you might end up with the value
being nothing, rather than what the customer set.

Walter

On Jun 30, 2010, at 10:36 AM, David Owen wrote:

Sorry I sould have been a little more specific I’m sending a hidden
field value alongside each text field for example “my value” to
accompany the use text field value.

If the user leaves these value as blank, these hidden fields “are”
still being sent when the ‘redbox’ is hidden by the script and Mals
then displays these unless I can disable them to “” nothing

This bits are inserted as code.

<input type="hidden" name="message_title[]" value="my value">
<input type="text" name="message[]" size="5">

so do I document.write the variables like I would use php to echo /
print

Or I suppose the simplest is to use the existing script to simply
hide() ?

David

On 30 Jun 2010, at 15:13, Walter Lee Davis wrote:

Certainly this can be done. The individual hidden fields would need
to have IDs added to them for this to work. I don’t believe that
the Form Setup dialog lets you do that, though, so you should
experiment with my FormFix Action in Page mode to see if that
cleans up that problem for you.

The syntax to put inside your switcheroo would be this:

$(‘theIdOfTheHiddenField’).setValue(‘123.45’);

But I think that overall, you might want to re-think how this whole
thing works. It might be simpler within Freeway to create each set
of options in its own “redbox”, stack them all on top of each
other, and then only show the one that is pertinent to the choice
in the picking list. There’s another thread on this list or maybe
the main FreewayTalk list from last week where I helped someone
build exactly that form for a Mals cart.

One thing that will definitely help you here is that any form
element that is hidden with JavaScript (not hidden in the sense of
) will not be submitted to the server. So if you
had a lot of form elements, but most of them had their display
property set to none through JavaScript (which is what happens when
you apply the Prototype function hide() to them) then they would be
missing from the form submission. So only the elements that you’ve
enabled through your picker will go anywhere.

Walter

On Jun 30, 2010, at 9:58 AM, David Owen wrote:

cartvalue1 =“changedvalue”;
cartvalue2 =“changedvalue”;


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

You say the form elements held within ‘redbox’ should not get sent to the server if using hide() ?

The script uses $(‘redbox’).hide(); And elements held within ‘redbox’ are being sent to the server

Is hide() working correctly?

hide-send

David

On 30 Jun 2010, at 15:36, David Owen wrote:

One thing that will definitely help you here is that any form element that is hidden with JavaScript (not hidden in the sense of ) will not be submitted to the server. So if you had a lot of form elements, but most of them had their display property set to none through JavaScript (which is what happens when you apply the Prototype function hide() to them) then they would be missing from the form submission. So only the elements that you’ve enabled through your picker will go anywhere.


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

Try sending the form as a POST rather than a GET. I get mixed results.
Safari seems to pass the elements along in the GET, but Firefox with
Tamper Data does not see them.

Walter

On Jun 30, 2010, at 11:01 AM, David Owen wrote:

You say the form elements held within ‘redbox’ should not get sent
to the server if using hide() ?

The script uses $(‘redbox’).hide(); And elements held within
‘redbox’ are being sent to the server

Is hide() working correctly?

hide-send

David

On 30 Jun 2010, at 15:36, David Owen wrote:

One thing that will definitely help you here is that any form
element that is hidden with JavaScript (not hidden in the sense of
) will not be submitted to the server. So if
you had a lot of form elements, but most of them had their display
property set to none through JavaScript (which is what happens
when you apply the Prototype function hide() to them) then they
would be missing from the form submission. So only the elements
that you’ve enabled through your picker will go anywhere.


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

This full site I’m working on is on MAMP on my machine here so cannot easily share.

Both Firefox and Safari is sending the POST data from my MAMP site to Mals specifically the message_title data to Mals is sent.

<input type="hidden" name="message_title[]" value="my value">

should hide() be stopping this? Should each hidden field be given and ID to specifically hide()

http://www.printlineadvertising.co.uk/demo/menuselect/hide-send.html

David

On 30 Jun 2010, at 16:08, Walter Lee Davis wrote:

Try sending the form as a POST rather than a GET. I get mixed results. Safari seems to pass the elements along in the GET, but Firefox with Tamper Data does not see them.

Walter

On Jun 30, 2010, at 11:01 AM, David Owen wrote:

You say the form elements held within ‘redbox’ should not get sent to the server if using hide() ?

The script uses $(‘redbox’).hide(); And elements held within ‘redbox’ are being sent to the server

Is hide() working correctly?

hide-send

David

On 30 Jun 2010, at 15:36, David Owen wrote:

One thing that will definitely help you here is that any form element that is hidden with JavaScript (not hidden in the sense of ) will not be submitted to the server. So if you had a lot of form elements, but most of them had their display property set to none through JavaScript (which is what happens when you apply the Prototype function hide() to them) then they would be missing from the form submission. So only the elements that you’ve enabled through your picker will go anywhere.


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

I am sorry, I was remembering the behavior of a form submitted through
Ajax (JavaScript submit without a page refresh) and thinking it was
the general case. It is not. A form field that has a value but is
hidden by CSS (display:none) still gets submitted with the form
contents during a normal form submission.

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);

Walter

On Jun 30, 2010, at 11:21 AM, David Owen wrote:

This full site I’m working on is on MAMP on my machine here so
cannot easily share.

Both Firefox and Safari is sending the POST data from my MAMP site
to Mals specifically the message_title data to Mals is sent.

<input type="hidden" name="message_title[]" value="my value">

should hide() be stopping this? Should each hidden field be given
and ID to specifically hide()

hide-send

David

On 30 Jun 2010, at 16:08, Walter Lee Davis wrote:

Try sending the form as a POST rather than a GET. I get mixed
results. Safari seems to pass the elements along in the GET, but
Firefox with Tamper Data does not see them.

Walter

On Jun 30, 2010, at 11:01 AM, David Owen wrote:

You say the form elements held within ‘redbox’ should not get sent
to the server if using hide() ?

The script uses $(‘redbox’).hide(); And elements held within
‘redbox’ are being sent to the server

Is hide() working correctly?

hide-send

David

On 30 Jun 2010, at 15:36, David Owen wrote:

One thing that will definitely help you here is that any form
element that is hidden with JavaScript (not hidden in the sense
of ) will not be submitted to the server. So
if you had a lot of form elements, but most of them had their
display property set to none through JavaScript (which is what
happens when you apply the Prototype function hide() to them)
then they would be missing from the form submission. So only the
elements that you’ve enabled through your picker will go anywhere.


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

Also, if you want to see what a form is up to, POST or GET it here: Reflector

Walter

On Jun 30, 2010, at 11:21 AM, David Owen wrote:

This full site I’m working on is on MAMP on my machine here so
cannot easily share.

Both Firefox and Safari is sending the POST data from my MAMP site
to Mals specifically the message_title data to Mals is sent.

<input type="hidden" name="message_title[]" value="my value">

should hide() be stopping this? Should each hidden field be given
and ID to specifically hide()

hide-send

David

On 30 Jun 2010, at 16:08, Walter Lee Davis wrote:

Try sending the form as a POST rather than a GET. I get mixed
results. Safari seems to pass the elements along in the GET, but
Firefox with Tamper Data does not see them.

Walter

On Jun 30, 2010, at 11:01 AM, David Owen wrote:

You say the form elements held within ‘redbox’ should not get sent
to the server if using hide() ?

The script uses $(‘redbox’).hide(); And elements held within
‘redbox’ are being sent to the server

Is hide() working correctly?

hide-send

David

On 30 Jun 2010, at 15:36, David Owen wrote:

One thing that will definitely help you here is that any form
element that is hidden with JavaScript (not hidden in the sense
of ) will not be submitted to the server. So
if you had a lot of form elements, but most of them had their
display property set to none through JavaScript (which is what
happens when you apply the Prototype function hide() to them)
then they would be missing from the form submission. So only the
elements that you’ve enabled through your picker will go anywhere.


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

To apply this function to as many forms as you might have on your page
all at once, do this:

$$('form').invoke('observe','submit',strip_hidden);

This (and the function itself) rely on Prototype and should be pasted
into the top Function Body dialog on Protaculous in order to work at
all.

Walter

On Jun 30, 2010, at 12:01 PM, Walter Lee Davis wrote:

I am sorry, I was remembering the behavior of a form submitted
through Ajax (JavaScript submit without a page refresh) and thinking
it was the general case. It is not. A form field that has a value
but is hidden by CSS (display:none) still gets submitted with the
form contents during a normal form submission.

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);

Walter

On Jun 30, 2010, at 11:21 AM, David Owen wrote:

This full site I’m working on is on MAMP on my machine here so
cannot easily share.

Both Firefox and Safari is sending the POST data from my MAMP site
to Mals specifically the message_title data to Mals is sent.

<input type="hidden" name="message_title[]" value="my value">

should hide() be stopping this? Should each hidden field be given
and ID to specifically hide()

hide-send

David

On 30 Jun 2010, at 16:08, Walter Lee Davis wrote:

Try sending the form as a POST rather than a GET. I get mixed
results. Safari seems to pass the elements along in the GET, but
Firefox with Tamper Data does not see them.

Walter

On Jun 30, 2010, at 11:01 AM, David Owen wrote:

You say the form elements held within ‘redbox’ should not get
sent to the server if using hide() ?

The script uses $(‘redbox’).hide(); And elements held within
‘redbox’ are being sent to the server

Is hide() working correctly?

http://www.printlineadvertising.co.uk/demo/menuselect/hide-
send.html

David

On 30 Jun 2010, at 15:36, David Owen wrote:

One thing that will definitely help you here is that any form
element that is hidden with JavaScript (not hidden in the sense
of ) will not be submitted to the server. So
if you had a lot of form elements, but most of them had their
display property set to none through JavaScript (which is what
happens when you apply the Prototype function hide() to them)
then they would be missing from the form submission. So only
the elements that you’ve enabled through your picker will go
anywhere.


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

OK thanks I will try this.

One last spanner, we’re checking a specific complete ‘Option 3’ to trigger the drop down extension to the form

if($F('List1') == 'Option 3' || $F('List1') == 'Option 2')

I’ve realised the real world form value does change depending where to form is coming from. There are unique word/s in the string to match from. The string ‘(add your prescription/lens below)’ is always in the last two in the menu

Does Javascript use wildcards? to compare?

David

On 30 Jun 2010, at 17:01, Walter Lee Davis wrote:

I am sorry, I was remembering the behavior of a form submitted through Ajax (JavaScript submit without a page refresh) and thinking it was the general case. It is not. A form field that has a value but is hidden by CSS (display:none) still gets submitted with the form contents during a normal form submission.

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);

Walter

On Jun 30, 2010, at 11:21 AM, David Owen wrote:

This full site I’m working on is on MAMP on my machine here so cannot easily share.

Both Firefox and Safari is sending the POST data from my MAMP site to Mals specifically the message_title data to Mals is sent.

<input type="hidden" name="message_title[]" value="my value">

should hide() be stopping this? Should each hidden field be given and ID to specifically hide()

hide-send

David

On 30 Jun 2010, at 16:08, Walter Lee Davis wrote:

Try sending the form as a POST rather than a GET. I get mixed results. Safari seems to pass the elements along in the GET, but Firefox with Tamper Data does not see them.

Walter

On Jun 30, 2010, at 11:01 AM, David Owen wrote:

You say the form elements held within ‘redbox’ should not get sent to the server if using hide() ?

The script uses $(‘redbox’).hide(); And elements held within ‘redbox’ are being sent to the server

Is hide() working correctly?

hide-send

David

On 30 Jun 2010, at 15:36, David Owen wrote:

One thing that will definitely help you here is that any form element that is hidden with JavaScript (not hidden in the sense of ) will not be submitted to the server. So if you had a lot of form elements, but most of them had their display property set to none through JavaScript (which is what happens when you apply the Prototype function hide() to them) then they would be missing from the form submission. So only the elements that you’ve enabled through your picker will go anywhere.


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

You can use regular expressions to match if a string or substring
exists in a string. Prototype also adds the helpful function
String.include which does the most common case for you: “does this
string include this other string?”.

if($F('List1').match(/foo/i)) // will hit on any string value that  
includes 'foo', 'FOO', 'Foo',...
if($F('List1').match(/foo/)) // will hit on any string value that  
includes 'foo'
if($F('List1').include('foo')) // will hit on any string value that  
includes 'foo'

I have a very fat O’Reilly book about regular expressions, they are an
entire college or graduate school course unto themselves. But suffice
it to say, you can do almost anything with them.

Walter

On Jun 30, 2010, at 12:25 PM, David Owen wrote:

OK thanks I will try this.

One last spanner, we’re checking a specific complete ‘Option 3’ to
trigger the drop down extension to the form

if($F('List1') == 'Option 3' || $F('List1') == 'Option 2')

I’ve realised the real world form value does change depending where
to form is coming from. There are unique word/s in the string to
match from. The string ‘(add your prescription/lens below)’ is
always in the last two in the menu

Does Javascript use wildcards? to compare?

David

On 30 Jun 2010, at 17:01, Walter Lee Davis wrote:

I am sorry, I was remembering the behavior of a form submitted
through Ajax (JavaScript submit without a page refresh) and
thinking it was the general case. It is not. A form field that has
a value but is hidden by CSS (display:none) still gets submitted
with the form contents during a normal form submission.

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);

Walter

On Jun 30, 2010, at 11:21 AM, David Owen wrote:

This full site I’m working on is on MAMP on my machine here so
cannot easily share.

Both Firefox and Safari is sending the POST data from my MAMP site
to Mals specifically the message_title data to Mals is sent.

<input type="hidden" name="message_title[]" value="my value">

should hide() be stopping this? Should each hidden field be given
and ID to specifically hide()

hide-send

David

On 30 Jun 2010, at 16:08, Walter Lee Davis wrote:

Try sending the form as a POST rather than a GET. I get mixed
results. Safari seems to pass the elements along in the GET, but
Firefox with Tamper Data does not see them.

Walter

On Jun 30, 2010, at 11:01 AM, David Owen wrote:

You say the form elements held within ‘redbox’ should not get
sent to the server if using hide() ?

The script uses $(‘redbox’).hide(); And elements held within
‘redbox’ are being sent to the server

Is hide() working correctly?

hide-send

David

On 30 Jun 2010, at 15:36, David Owen wrote:

One thing that will definitely help you here is that any form
element that is hidden with JavaScript (not hidden in the
sense of ) will not be submitted to the
server. So if you had a lot of form elements, but most of them
had their display property set to none through JavaScript
(which is what happens when you apply the Prototype function
hide() to them) then they would be missing from the form
submission. So only the elements that you’ve enabled through
your picker will go anywhere.


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


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

Thanks it’s all soaking in.

I do find if things go wrong there is sometimes very little feedback to what is happening.

David

On 30 Jun 2010, at 17:36, Walter Lee Davis wrote:

I have a very fat O’Reilly book about regular expressions, they are an entire college or graduate school course unto themselves. But suffice it to say, you can do almost anything with them.


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

If you haven’t already, enable the Developer menu in Safari or install Firebug in Firefox. Then in Safari, choose Develop/Show Error Console or in Firefox, click on the little bug in the lower-right corner of the window. That will show you all the ugliness. Sometimes the error messages approach English in their clarity, very often not. But copying and pasting error messages into Google is a time-honored way to debug your scripts!

Walter


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

All working and good to go except the disabling of the form element on submission.

http://www.printlineadvertising.co.uk/demo/menuselect/findmenuanddisab.html

Where in the document/how should the script go?

(I’m OK just inserting into Freeway just need to know the code position and I will reverse engineer back into Freeway interface ~ e.g. I’m not using any Protaculous actions in this instance) personally it helps me understanding what is going on by interacting with the raw code working in situ.

(I like the page: Reflector very useful)

David

On 30 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

I’m getting an error :frowning:

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

http://www.printlineadvertising.co.uk/demo/menuselect/findmenuanddisab.html

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

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

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)

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

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

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

Yay! got it. Boy this Javascript is fickle

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