Re: [Phplib-users] oohForm text element with multiple attribute
Brought to you by:
nhruby,
richardarcher
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] |