Doubts in .length function

1

In my case I'm picking up how many records are inside the variable. But the .length function determines that when there is only one record it is undefined , and it should show that there is a record in it. Is this some kind of function error, or is there a way to fix it? Or is there some other method I can use?

I'm storing this way:

function insert_info(){
    w_qtde_info = document.forms['my_form'].blc_info.length;

}

    <form name="my_form"  method="post">
    <table width="100%">
    <tr>
    <td>
<?php
        while($w_cont <= $w_opc)
        { 
        print('<input type="radio" name="blc_info" value="">');
         } 
        print('<input type="button" onClick="insert_info();" value=">>">');
?>
    </td>
    </tr>
    </table>
    </form>

w_opc is determined by the user. That is, he will add the radios (according to the example) according to the value that the user has determined!

Obs: I took the part of php as a reference for: Text radio

    
asked by anonymous 03.09.2014 / 14:42

1 answer

1

Why do not you do this?

   function insert_info(){
        w_qtde_info = document.forms['my_form'].blc_info.length || [];
    }

So if your query returns undefined you will not break a query on w_qtde_info.length

    
03.09.2014 / 15:18