basic javascript syntax question regarding attributes and functions [SOLVED]
I'm just starting with javascript. I tinkered this very simple function, that enables / disables two textboxes when a checkbox is clicked.
VB Code:
<script language="javascript">
<!--
function enableField(tb1, tb2)
{
with (tb1)
{
disabled = !document.form1.checkbox.checked
}
with (tb2)
{
disabled = !document.form1.checkbox.checked
}
}
//-->
</script>
I want to know how can I access the properties of an html object without using the with (attribute) syntax. Basically doing it inline, replacing the name of the object with the attribute I passed to the function.
Instead of:
with (tb2)
{
disabled = !document.form1.checkbox.checked
}
Do:
document.form1.[attribute I passed].disabled = !document.form1.checkbox.checked
How can I construct that dynamic path?
Thank you
HoraShadow
Re: basic javascript syntax question regarding attributes and functions
onClick="enableField(this)"
To pass a HTML element to a function, just use 'this' as an argument, and then you can use it inside the function,
argument1.disabled = document.form1.checkbox.checked
I didn't even know there was a with with Javascript :p
Re: basic javascript syntax question regarding attributes and functions
Ahhh! now I get it.
Thanks man!
HoraShadow