Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

way for a checkbox to get the form that it is in 2

Status
Not open for further replies.

webslinga

Programmer
Joined
Jun 20, 2006
Messages
55
Location
US
Hey all

I have a checkbox that is placed inside a form. Is there a way for this checkbox to know which form it is in. A fictitious piece of code to just illustrate my example would be something like:
Code:
<input type="checkbox" name="all" id="all" value="all" onClick="toggleAll(document.getElementById('[b]this.form[/b]'),'roleCheck', this)" />
 
Although you wouldn't need to pass "this.form" at all, as you're already passing "this" as the third parameter, so you could pick up the ".form" property from that.

Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
so hold on... I was right in typing in this.form? What does that return back to me? Is my syntax correct?
 
webslinga, you were using:
document.getElementById('this.form')
First, you have this.form inside quotes which would cause it to be treated as a literal value, not as a reference to the form.
Second, document.getElementById('somename') will refer to the element that has an ID tag of the same name as the one you include in the quotes, in this case an id of somename. It is a way of referencing an element whose name you already know.
What you were trying to do is pass a reference to the form object inside your function call.

Dan's code:
Code:
toggleAll(this.form, ...)
is just showing you that within the function call you can use the words this.form to directly send the reference.

In other words you would replace your original line of:
Code:
onClick="toggleAll(document.getElementById('this.form'),'roleCheck', this)"

With this:
Code:
onClick="toggleAll(this.form,'roleCheck', this)"

But as Dan noted above, you are already passing in a reference to the field the event is occuring from:
Code:
onClick="toggleAll(this.form,'roleCheck', [COLOR=red ]this[/color])"

When you have a reference to the object you can modify it directly you do not have to specify the form that it is in.

You may however need to know the form because you want to perform actions on other fields of the same form in which case using this.form in the function call will work.


Google, you're my hero!
 
I enjoyed that post.

I don't know the answer but my good friend Google does.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top