Hi:
I have a JSP page in my Struts application that displays months in a <Table> as followed:
<table><TBODY class=dates id=anotherList onclick="getDate()" >
<tr>
<td style="cursor:hand" onclick="selectedMth=1">Jan</td>
<td style="cursor:hand" onclick="selectedMth=2">Feb</td>
<td style="cursor:hand" onclick="selectedMth=3">Mar</td>
</tr>
</TBODY></table>
I also have an input TEXT field that is to pass a combination of 'mth/yr' to the struts Action class, so my input field is as followed:
<html:text property='mth_yr' name='mth_yr' id='mth_yr' />
I also have a JavaScript function 'getDate()' to dynamically update the above TEXT field when the month that is clicked from the above <Table>
var selectedMth = 1; // global varaible
function getDate()
{
var whichYr = document.getElementById('year')[document.getElementById('year').selectedIndex].text;
document.getElementByNme('mth_yr').value= selectedMth + "/" + whichYr;
}
When I clicked any of the month from the above month <Table>, I got the following error:
Error: Object doesn't support property or method getElementByName. [note: I also try document.getElemenByID('mth_yr'), same error]
I can see from JavaScript debugging that when I clicked (e.g. Mar). 'selectedMth' will be set to '3' (so the table/onclick works), but the <html:text> will not be updated and I got the above Error.
Now, if I change the above <html:text> to standard html <TEXT> field as followed:
<input type="text" name="mth_yr" id="mth_yr"/>
then the <TEXT> field will be updated to (e.g. 3) with no error. But the problem with this standard html <TEXT> field, I will not have the 'property' 'mth_yr' to be passed to the Struts Action form.
So bottom line: how do I make the above work such that when I select a 'month' from the above table, the INPUT Text field will be updated with the mth-yr value and at the same time, this field will be passed to the Action class as a property.
Can anyone help?
Thanks,
sportyNerd