• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 5491
  • Last Modified:

How to get parent object from child object?

I've two problems.
Retreiving parent objects.

1. Inside a form I've a button. Now on the click of button , I invoke a method. Now how to get the form object reference inside the button or method, which button invokes.

2.
<button onclick"x()" >SOme Button</button>

function x()
{
   /* code which gets the button object reference */
}

Now inside the function x(), I need the "button" object reference. How do I get it?.
0
maheshexp
Asked:
maheshexp
1 Solution
 
hernst42Commented:
use "this" to give the button object to the function like
function x(button) { ... }

<button onclick="x(this)">...

The in x you can access the button via the variable button
0
 
knightEknightCommented:
use this.form

<button onclick"x(this.form)" >
0
 
maheshexpAuthor Commented:
No my fuction x() doesn't take any arguments. That's the problem here...
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
dakydCommented:
Is there something preventing you from changing the x() function?  Passing the argument is the simplest solution to your question, so if you can go that route, you should.
0
 
maheshexpAuthor Commented:
yeah, the function x() signature is automatically generated. I can only have logic for that using the given arguments. Other than that, I can't change the signature.
0
 
hernst42Commented:
can you add an id to the form name or do you have multiple forms on the page? If you can't change the signature and can't use ids it's AFAIK not possible to get the caller-object of the function.
0
 
LeeKowalkowskiCommented:
It doesn't matter whether your function signature has any arguments, you can always pass a function arguments and then inspect the arguments array.

  function x()
  {
    var button = x.arguments[0];
  }

  ...
  <button onclick="x(this)">

--
Lee
0
 
Computer101Commented:
Forced accept.

Computer101
EE Admin
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now