PDA

View Full Version : is there any way to know from what object property the arg is coming from ?


frontline
12-08-2002, 03:19 PM
Hello
simple question (i think) .is there any way in js when i give a function the parameters something like this:
< input type="text" name="foo1" id="foo2" value="foo3" onclick="MyFunc(this.name,this.id,this.value) >
now in the MyFunc(x,y,z) is there any way to know that the this.name is coming from the "name" property of the <input type="text">
and the this.id is coming from the "id" property of the <input type="text"> and so on .. this is in case i pass the args this way.
i mean beside the values of the properties i need to know the property type/name it came's from .
hope i made my self clear
thanks

Graeme Hackston
12-08-2002, 03:45 PM
Where y is the name being passed

function test(y) {
if (y == 'foo1') {
//do stuff
}
}

Is that what you mean?

frontline
12-08-2002, 04:06 PM
no ..
i will not know that values of the properties , i need to know from what property of the object in this case :
the <input type=text> html object and the properties are name,id,value so i need to know from where every arg came from
that is from what property in the object .
do i make my self clearer now?
thanks

Graeme Hackston
12-08-2002, 04:15 PM
Sorry I'm not clear on what you mean. Do you need to know if it came from an input type=text?

jkd
12-08-2002, 04:36 PM
function MyFunc(a, b, c) {
var origin = arguments.callee.caller.arguments[0].currentTarget;
if (origin.getAttribute('name') == a) {
// a is the name
}
}

Borgtex
12-08-2002, 06:31 PM
Why don't do it in the easy way?

< input type="text" name="foo1" id="foo2" value="foo3" onclick="MyFunc(this) >


MyFunc(x)
{
//and now use x.id, x.name, x.value, .....
}