1
In my case I’m picking up how many records are within the variable. But the function .length determines that when there is only one record it is undefined, it should show that there is a record in it. Is this a mistake of the function itself or is there a way to fix it? Or is there some other method I can use?
I’m storing it like this:
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, will add the radios (as per example) according to the value determined by the user!
Obs: I took the php part as a reference : Text radio
i would like to see the body of your form.... has how Voce post?
– MarceloBoni
What is
blc_info? an input field?– Sergio
Yes, blc_info is an input!
– Bruno
lengthin this case it is not to be used as a function, but rather as a property. I also found nothing in the specification about this behavior you describe. Thislengthis native or is it something that someone on your team has implemented?– Oralista de Sistemas
@Renan he is very native! Because I ended up testing with other items (radio with certain values) and it occurs the same error!
– Bruno
I tested it here in Chrome and this property always gives Undefined for inputs and textareas. You speak of "records within a variable" - are these records actually properties that you are entering into the input? If you have more code that moves this input, edit the question to include this, ok?
– Oralista de Sistemas
Bruno, so what you want is
valueof him no? likew_qtde_info = document.forms['my_form'].blc_info.value;– Sergio
No @Sergio, I need to know how many records were "included" within the variable! I’m going to post an example with radio that I think is easier!
– Bruno
Bruno, that
whileis PHP?– Sergio
@Sergio, Yes (I edited a bit fast)!
– Bruno
In this case your javascript is correct, what you have is errors in PHP. Missing a
echobefore HTML and missing open and close PHP... know how to do? another question is your function does not return anything. It is complete?– Sergio
Yes @Sergio it is complete. Missed the opening of PHP because I finished editing fast and I forgot to put here!
– Bruno
Bruno, this function does nothing. That is, it does not answer anything. What do you want to do with the number that this variable has? At least one
alert(w_qtde_info);within the function?– Sergio