[Zope] Form data type coercion syntax and javascript

2001-01-17 Thread Mayers, Philip J

Not a problem per-se, just a query - how are people dealing with things like
this:

dtml-var standard_html_header
FORM
SELECT MULTIPLE NAME="test"
/SELECT

SCRIPT LANGUAGE="JavaScript"

function populate(form) {
  for (var i=0;i4;i++) {
form.test.options[i] = new Option("Red"+i,"color_red");
if (i == 0)
  form.test.options[i].selected = true;
  }
  return false;
}

/SCRIPT

INPUT TYPE="BUTTON" onClick="populate(this.form)" VALUE="Fill in"
INPUT TYPE="SUBMIT" VALUE="Go"
/FORM

dtml-var standard_html_footer

If a user selects multiple values, of the dynamic list, Zope will coerce
them to a list when the form is input. *BUT*, if they select a single value,
it'll be a single string/integer. Normally, you'd do this:

SELECT NAME="test:list"

But how do you access it from JavaScript then? I'm doing this:

function populate(form) {

  var list = form;

  for (var j=0;jform.length;j++) {
if (form.elements[j].name == "test:list")
  list = form.elements[j];
  }

  if (list == form)
return false;

  for (var i=0;i4;i++) {
list.options[i] = new Option("Red"+i,"color_red");
if (i == 0)
  list.options[i].selected = true;
  }
  return false;
}

Anything more elegant?

Regards,
Phil

+--+
| Phil Mayers, Network Support |
| Centre for Computing Services|
| Imperial College |
+--+  

___
Zope maillist  -  [EMAIL PROTECTED]
http://lists.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://lists.zope.org/mailman/listinfo/zope-announce
 http://lists.zope.org/mailman/listinfo/zope-dev )




RE: [Zope] Form data type coercion syntax and javascript

2001-01-17 Thread Max Møller Rasmussen

From: Mayers, Philip J [mailto:[EMAIL PROTECTED]]

Not a problem per-se, just a query - how are people dealing with things
like
this:

snipped lots of stuff...

Anything more elegant?

I don't know if it is something like this you mean:

self.document.form['test:list'].value = 'stuff to fill in';

or perhaps?

self.document.form['test:list'] = new Option("Red"+i,"color_red");

regards Max M

___
Zope maillist  -  [EMAIL PROTECTED]
http://lists.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://lists.zope.org/mailman/listinfo/zope-announce
 http://lists.zope.org/mailman/listinfo/zope-dev )




Re: [Zope] Form data type coercion syntax and javascript

2001-01-17 Thread Oleg Broytmann

On Wed, 17 Jan 2001, Mayers, Philip J wrote:
 SELECT NAME="test:list"

 But how do you access it from JavaScript then? I'm doing this:
   list = form.elements[j];

  list = form.elements["test:list"];

Oleg.

 Oleg Broytmann http://www.zope.org/Members/phd/ [EMAIL PROTECTED]
   Programmers don't die, they just GOSUB without RETURN.


___
Zope maillist  -  [EMAIL PROTECTED]
http://lists.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://lists.zope.org/mailman/listinfo/zope-announce
 http://lists.zope.org/mailman/listinfo/zope-dev )