E
es330td
I have an application that puts a table of values on a page along with
a form whereby the user may add a value. I need to make sure that the
value does not already exist in the table so I want to run a onBlur
function to check the value when they are ready to submit it. The
cells in question are dynamically generated so I do not know before
the page loads how many cells there will be. All cells have an ID
value of TDx, e.g. TD1 or TD14
I tried this code:
<form>
<table><tr><td id="td1">1/2/2007</td><td id="td2">3/14/2007</td></tr></
table>
<input type=text name="myvaluetotest" onBlur="checkvalue(this)">
</form>
<script language=javascript>
function checkvalue(myvar) {
var ary,i;
ary = document.getElementsByTagName("TD")
for(i in ary)
{
alert(i + ' ' + document.getElementById('td1').innerText);
}
}
</script>
When I run this onBlur it will run through the loop and pop up an
alert box with TD1 1/2/2007 and then one with TD2 3/14/2007. As a
result I know that the ary = assignment is working.
However, if I try to substitute i for the 'td1' in the getElementById
property it tells me Object Required. What is the right way to do
this?
a form whereby the user may add a value. I need to make sure that the
value does not already exist in the table so I want to run a onBlur
function to check the value when they are ready to submit it. The
cells in question are dynamically generated so I do not know before
the page loads how many cells there will be. All cells have an ID
value of TDx, e.g. TD1 or TD14
I tried this code:
<form>
<table><tr><td id="td1">1/2/2007</td><td id="td2">3/14/2007</td></tr></
table>
<input type=text name="myvaluetotest" onBlur="checkvalue(this)">
</form>
<script language=javascript>
function checkvalue(myvar) {
var ary,i;
ary = document.getElementsByTagName("TD")
for(i in ary)
{
alert(i + ' ' + document.getElementById('td1').innerText);
}
}
</script>
When I run this onBlur it will run through the loop and pop up an
alert box with TD1 1/2/2007 and then one with TD2 3/14/2007. As a
result I know that the ary = assignment is working.
However, if I try to substitute i for the 'td1' in the getElementById
property it tells me Object Required. What is the right way to do
this?