Hello,

I solved the DOM problem. While the dynamically generated radio buttons
could not be read by their name attribute, they could be read by their
id attribute. I had mistakenly capitalized the D at the end of
"getElementById." Below is an adaption of a script from page 749 of the
second edition of O'Reilly's "Dynamic HTML: The Definitive Reference"
that can read these buttons.

<script type="text/javascript">

  function read_multi(elementName, count){
    for(var i = 0; i < count; i++) {
      var a_button = document.getElementById(elementName + '_' + i);
      if(a_button.checked){
        alert('The value of the chosen button is ' + a_button.value);
      }
    }
  }

</script>

Thank you for taking the time to read this topic.

--
Mountain Man

On Jan 25, 1:44 pm, "Mountain Man" <[EMAIL PROTECTED]> wrote:
> Hello,
>
> I searched Cake PHP for "DOM" and got 4 pages of results, none of which
> appeared to address this question.
>
> I am having a problem with code adapted from the first edition of
> "Programming PHP." This code dynamically generates checkboxes or radio
> buttons that retain their settings when the form is submitted without
> passing validation.
>
> The problem is that these dynamically generated form controls almost
> never appear in the DOM when the page loads. I am only aware of one
> instance with Firefox 2 where I was able to access these form controls
> with DHTML. My code example appears below.
>
> <?php
>
> function make_radio ($name, $query, $options) {
>   $i = 0;
>   foreach ($options as $value => $label) {
>     printf('<label><input type="radio" name="%s[]" id="%s_%s"
> value="%s" ',
>             $name, $name, $i, $value);
>     if (in_array($value, $query)) {echo "checked ";}
>     echo "/> $label</label><br />\n";
>     $i++;
>   }
>
> }if (! is_array($own_files)) { $own_files = array(); }
>
> $preference1 = array(
>   'Yes'  => 'Yes',
>   'No'  => 'No',
>   );
>
> make_radio (own_files, $own_files, $preference1);
>
> ?>
>
> As I said before, there was one instance where these form controls did
> make it into the DOM. Otherwise, the following examples test as
> undefined.
>
> <script type="text/javascript">
>   document.forms[0].own_files[0];
>   document.forms[0].own_files[1];
>   document.getElementByID('own_files_0');
>   document.getElementByID('own_files_1');
> </script>
>
> Does anyone know how to get dynamically generated form controls into
> the DOM on a reliable basis? I have tested the above JavaScript in
> Firefox 2, IE 7, and Opera 9 for Windows XP. Thank you to all who can
> shed light on this problem.
> 
> --
> Mountain Man


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to