Thread: [Phplib-users] oohForm text element with multiple attribute
Brought to you by:
nhruby,
richardarcher
From: Andres B. Z. <aba...@ei...> - 2003-08-22 23:48:33
|
Hello: In Javascript, if multiple objects on the same form have the same NAME attribute (eg. <input type=text name=myField> ), an array of the given NAME (myField) is created automatically. Elements are indexed in source order starting at 0. So references to document.theForm.myField[0] are valid. Now, I am using this piece of php code: for ($i=0;$i<$n;$i++) { $f->add_element(array("type"=>"text", "name"=>"myField", "multiple"=>1, "value"=>"$nombre")); } And I have found that oohform prints the form elements as: <input name=myField[] value=''> The "[]" appended to the element name fools the javascript interpreter so I cant make reference to the elements. How can I make oohform to print the element name without the "[]" ? Thanks Andres |
From: Andres B. Z. <aba...@ei...> - 2003-08-25 18:32:02
|
Hello again: I went into the oohForm class files and I edited the line where a multiple text field is printed so no more problems with the appended "[]". But I still have a problem, it is not posible to give different values to the various instances of a multiple text field. By now, I wonder if I am trying to do something that oohForm does not offer... Being more especific... Can oohForm deal with multiple text fields with the same name and different values? Thank you very much... Andres -----Original Message----- From: php...@li... [mailto:php...@li...]On Behalf Of Andres Barreto Zicare Sent: Viernes, 22 de Agosto de 2003 12:21 p.m. To: php...@li... Subject: [Phplib-users] oohForm text element with multiple attribute Hello: In Javascript, if multiple objects on the same form have the same NAME attribute (eg. <input type=text name=myField> ), an array of the given NAME (myField) is created automatically. Elements are indexed in source order starting at 0. So references to document.theForm.myField[0] are valid. Now, I am using this piece of php code: for ($i=0;$i<$n;$i++) { $f->add_element(array("type"=>"text", "name"=>"myField", "multiple"=>1, "value"=>"$nombre")); } And I have found that oohform prints the form elements as: <input name=myField[] value=''> The "[]" appended to the element name fools the javascript interpreter so I cant make reference to the elements. How can I make oohform to print the element name without the "[]" ? Thanks Andres ------------------------------------------------------- This SF.net email is sponsored by: VM Ware With VMware you can run multiple operating systems on a single machine. WITHOUT REBOOTING! Mix Linux / Windows / Novell virtual machines at the same time. Free trial click here:http://www.vmware.com/wl/offer/358/0 _______________________________________________ Phplib-users mailing list Php...@li... https://lists.sourceforge.net/lists/listinfo/phplib-users |
From: Nathaniel P. <np...@te...> - 2003-08-25 23:43:37
|
There have been some problems with using JavaScript on form inputs that have "[]" in their name before. Some excellent solutions can be found in the user contributed notes in the PHP manual: http://www.php.net/manual/en/language.types.array.php Basically the solutions boil down to doing one of the following: 1) Use the alternate Javascript syntax to access the form, i.e.: document.theForm.elements["myField[0]"].value This will only work if each input has a unique name. In other words, if you have multiple inputs and all of them are named "myField[]", this won't work. However, this is also the most foolproof method of doing it, since it won't break if you move the HTML form elements around, as with method #2. All you have to do is make sure that OOHforms outputs an index number along with each form name, so that it looks like <input name="myField[$i]"...> where $i is a unique number for each form element, instead of <input name="myField[]"> 2) Use the generic JavaScript elements[] array to access it, i.e.: for (i = 0; i <= frm.elements.length; i++) { document.theForm.elements[i].value } The disadvantage is that if you move your form elements around much, you'll break your javascripts. 3) You might also experiment with using the HTML ID attribute to do it, however I'm not sure if it will work: <script language="javascript"> //UNTESTED JAVASCRIPT - Use at own risk //Make sure your form elements are done like this: //<input type="text" name="myField[]" id="myField1"> //<input type="text" name="myField[]" id="myField2"> //and so on document.writeln(document.getElementById("myField1").value); document.writeln(document.getElementById("myField2").value); </script> You will need to make sure that each HTML ID attribute is given a different name. This one is almost like method #1, but you don't have to worry about giving each element a unique NAME attribute. I will leave a specific implementation within OOHforms as an excersize to the reader, since I haven't bothered much with that particular class and wouldn't know exactly where you'd need to modify it. _________________________________ Nathaniel Price Webmaster <http://www.tesseract.net> ----- Original Message ----- From: "Andres Barreto Zicare" <aba...@ei...> To: <php...@li...> Sent: Monday, August 25, 2003 12:30 PM Subject: [Phplib-users] oohForm text element with multiple attribute > > Hello again: > I went into the oohForm class files and I edited the line where a multiple > text field is printed so no more problems with the appended "[]". But I > still have a problem, it is not posible to give different values to the > various instances of a multiple text field. By now, I wonder if I am trying > to do something that oohForm does not offer... Being more especific... Can > oohForm deal with multiple text fields with the same name and different > values? > Thank you very much... > Andres [snip] |