S
Sathyaish
I am no JavaScript progammer, and unfortunately am having to babysit an
old code base that has a lot of JavaScript in it.
I have two questions:
(1) Can two HTML controls have the same name? It looks like the obvious
answer is NO.
(2) What if? What if the developer has given two HTML controls the same
name, i.e has created the same button more than once with exactly the
same name and all other attributes? What happens then?
Ok, before you call me lazy, let me tell you, I tried it. Here's what I
did on a spike solution.
<HTML>
<SCRIPT>
function doFoo()
{
document.forms[0].edt.disabled=!document.forms[0].edt.disabled;
}
</SCRIPT>
<FORM name="frmFoo">
<INPUT type="button" value="Edit" name="edt" onClick="return doFoo()"/>
<INPUT type="button" value="Edit" name="edt" onClick="return doFoo()"/>
</FORM>
</HTML>
Like I expected, clicking any of the buttons did not disable either of
them.
So, I wanted to do something like this:
For Each HTML Control In The Form On The Document
If The HTML Control Has a Value Of Edit Then
Disable It, or do something with it like show me its name and
value
End If
Next HTML Control
So, here's what I did:
<HTML>
<SCRIPT>
function doFoo()
{
alert(document.forms[0].children.length)
for(i=0; i<=document.forms[0].children.length-1; i++)
{
alert(document.forms[0].children.name)
if (document.forms[0].children.value == 'Edit')
document.forms[0].children.disabled=false;
}
}
</SCRIPT>
<FORM name="frmFoo">
<INPUT type="button" value="Edit" name="edt" onClick="return doFoo()"/>
<INPUT type="button" value="Edit" name="edt" onClick="return doFoo()"/>
</FORM>
</HTML>
And lo! as I expected, the form has just one element reference that is
valid and the other as an invalid reference.
Given this situation on my "actual" code that I am babysitting (someone
else wrote it), and it is HUGE, and it has all JavaScript and HTML
elements dynamically generated from ASP code and some strong glue by
way of screwed up logic, what options do I have other than re-write the
page?
I am running IE 6 on Win 2000, if that is relevant.
old code base that has a lot of JavaScript in it.
I have two questions:
(1) Can two HTML controls have the same name? It looks like the obvious
answer is NO.
(2) What if? What if the developer has given two HTML controls the same
name, i.e has created the same button more than once with exactly the
same name and all other attributes? What happens then?
Ok, before you call me lazy, let me tell you, I tried it. Here's what I
did on a spike solution.
<HTML>
<SCRIPT>
function doFoo()
{
document.forms[0].edt.disabled=!document.forms[0].edt.disabled;
}
</SCRIPT>
<FORM name="frmFoo">
<INPUT type="button" value="Edit" name="edt" onClick="return doFoo()"/>
<INPUT type="button" value="Edit" name="edt" onClick="return doFoo()"/>
</FORM>
</HTML>
Like I expected, clicking any of the buttons did not disable either of
them.
So, I wanted to do something like this:
For Each HTML Control In The Form On The Document
If The HTML Control Has a Value Of Edit Then
Disable It, or do something with it like show me its name and
value
End If
Next HTML Control
So, here's what I did:
<HTML>
<SCRIPT>
function doFoo()
{
alert(document.forms[0].children.length)
for(i=0; i<=document.forms[0].children.length-1; i++)
{
alert(document.forms[0].children.name)
if (document.forms[0].children.value == 'Edit')
document.forms[0].children.disabled=false;
}
}
</SCRIPT>
<FORM name="frmFoo">
<INPUT type="button" value="Edit" name="edt" onClick="return doFoo()"/>
<INPUT type="button" value="Edit" name="edt" onClick="return doFoo()"/>
</FORM>
</HTML>
And lo! as I expected, the form has just one element reference that is
valid and the other as an invalid reference.
Given this situation on my "actual" code that I am babysitting (someone
else wrote it), and it is HUGE, and it has all JavaScript and HTML
elements dynamically generated from ASP code and some strong glue by
way of screwed up logic, what options do I have other than re-write the
page?
I am running IE 6 on Win 2000, if that is relevant.