Fill Select JSN Uninform from a folder

0

I have to fill out a specific selection of a JSN Uniform form with the files of a directory, the problem is that clicking on the fill button just reads me a file:

How can I read and load all the files in my folder in that select ("45")?

Code:

echo '<input type="button" value="Llenar Select" onclick="ShowSelected()">';

$directorio = "D:\letritastv\imagenes";
$sizekb = 0.0 ;
$sizemb = 0.0 ;
$dir=opendir($directorio);

while ($file = readdir($dir))
{
    if ($file != "." && $file != "..")
    {
       $variable_php=$file;
         echo '<script type="text/javascript">';
         echo 'function ShowSelected(){';
         echo 'var mivar = " '.$variable_php.' "; ';
         echo 'variable = new Option(mivar);';
         echo 'var x = document.getElementById("45");';
         echo 'x.options[1]=variable;';
         echo '}';
         echo '</script>';
   }
}

    
asked by Estefani_Sanchez 24.04.2017 в 21:41
source

1 answer

0

First, this set of instructions

echo '<script type="text/javascript">';
echo 'function ShowSelected(){';
echo 'var mivar = " '.$variable_php.' "; ';
echo 'variable = new Option(mivar);';
echo 'var x = document.getElementById("45");';
echo 'x.options[1]=variable;';
echo '}';
echo '</script>';

are inside the while, with which you are defining the function ShowSelected several times (you can press Ctrl + U or look for the option See source code of the web page, so you can see that this function is defined several times) .

Second, x.options[1] refers to the same select option, again and again.

Correct it would be that with the while of php you generate an arrangement, and that you use it within ShowSelected (a single function, you should not repeat it), to go creating the different options, of course changing the index (in your code it is always 1 ).

PS: casually here there is an example related to what you want.

    
answered by 24.04.2017 в 22:09