Jeff Stone
Jeff Stone

Reputation: 319

Javascript return two values in onchange function

I need to return two values in a text input. Here's what I'm trying:

<input type="text" size="2" name="disOrd[<? echo $usersArray[$x]['id']; ?>]" 
value="<? echo $usersArray[$x]['disOrd']; ?>" 
onchange="updateAgentOrder(this.name,this.value)" />

It only returns the first one, not the second one. Is this even possible to do? I absolutely need both.

Here's what updateAgentOrder does, just a temporary deal to get the values:

function updateAgentOrder(x,y){
alert(x,y);
}

If I change the order of this.name and this.value, it will only show the first one.

Upvotes: 1

Views: 851

Answers (2)

Niet the Dark Absol
Niet the Dark Absol

Reputation: 324650

alert only takes one argument, the thing to alert.

alert(x);
alert(y);

This will show two alerts, one after the other, showing each of the two values.

Upvotes: 3

feeela
feeela

Reputation: 29932

No, you can't create functions with multiple return values in JS. (as in Python or Go) If you need to return multiple values from a function you need to wrap them in a literal object:

return {
    name: name,
    value: value
};

Upvotes: 1

Related Questions