why this Javascript function doesn't work?
Posted
by udaya
on Stack Overflow
See other posts from Stack Overflow
or by udaya
Published on 2010-03-23T05:03:11Z
Indexed on
2010/03/23
5:11 UTC
Read the original article
Hit count: 398
JavaScript
|php
I use the following javascript function,
function get_check_value(formId,checkboxId,TxtboxId)
{
alert(formId);
var c_value = "";
for (var i=0; i < document.formId.checkboxId.length; i++)
{
if (document.formId.checkboxId[i].checked)
{
c_value = c_value + document.formId.checkboxId[i].value + "\n";
}
}
alert(c_value);
document.getElementById(TxtboxId).value= c_value;
// alert(c_value.value);
}
and my php page has this,
<form name="orderform" id="orderform">
<input type="text" name="chId" id="chId" >
<table align="center" border="0">
<tr>
<td>Country</td>
</tr>
<? foreach($country as $row){ ?>
<tr>
<td><?= $row['dbCountry']; ?></td>
<td><input type="checkbox" name="CountrycheckId" id="CountrycheckId" value="<?= $row['dbCountryId']; ?> " onClick="get_check_value('orderform','CountrycheckId','chId')"></td>
<? } ?>
</tr>
</table>
</form>
I am getting formname,checkboxid,textid in alerts inside the javascript function... But
the problem is with the line
for (var i=0; i < document.formId.checkboxId.length; i++)
Webdeveloper toolbar shows this error
document.formId is undefined
© Stack Overflow or respective owner