/    Sign up×
Community /Pin to ProfileBookmark

multiple returns

Hi, I’m a newbie at the forum and at JavaScript. Even when I was a programmer for 25 years, I’m just starting with JS.

I have a question: I’m tryng to obtain 2 results from a function, but I can’t ?

Example:

function doSomething(a, b) {
a += 1
b += 2
return ????????????
}

I need to call this function, but I need to obtain the new [b]a[/b] and [b]b[/b] values.

Can I do this in JS?

Thanks

to post a comment
JavaScript

6 Comments(s)

Copy linkTweet thisAlerts:
@superdave77Jul 28.2004 — Hey, I'm kind of new with the JS too....it can definitely do what you want and here may be how.....

Are you trying to get values from forms? either way, you have to tell JS where in the document (DOM) your values are coming from.....

[code=php]<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>

<head>

<title>A DysFunctional JavaScript</title>
<script>
// a function
function aFunction() {
var a
var b

var a = (document.aForm.aField1.value);
var b = (document.aForm.aField2.value);

if (a <= 54) {
window.close();
return false;
}
else if (b <= 3); {
alert("Ouch!!");
return false;
}
return true;

}
</script>
</head>

<body>
<form id="aForm" name="aForm" action="" method="Post" onsubmit="aFunction();">
<input type="text" id="aField1" name="aField1" maxlength="3" size="3">
<input type="text" id="aField2" name="aField2" size="2" maxlength="2">
<input type="submit" id="submit" name="submit" value="Submit to me">
<input type="reset" id="reset" name="reset" value="Reset Me!">
</form>
</body>

</html>
[/code]


Let me know if that answers anything about anything for you.......
Copy linkTweet thisAlerts:
@GerarDreamauthorJul 28.2004 — Thanks, but no. I'm not using a form.

I'm programming a really complex site and I have almost finished it ?

I'm trying to add functionally to navigation buttons. I have named the photoes like: mount00.jpg; mount01.jpg; and so. I have 21 different folders with 15 to 85 photoes inide.

What I'm trying to do is a function that changes the number (the name) of the photo: prev button: photo -1; next button: photo +1.

I have made the string function but I need to obtain the new name and the new number (I'm controlling not <0 and not >number of photos).

Well, I'm sorry for my poor english and I hope you can understand me.
Copy linkTweet thisAlerts:
@superdave77Jul 28.2004 — It's no problem....

Quisiera ir a Buenos Aires en el futuro....

Can't you just name the photos all the same thing and then put them into an array and write a command that that runs when you click your 'next' button?

by name the same thing I mean

<img src="image1.gif" name="myPhotos" id="myPhotos" alt="">

<img src="image2.gif" name="myPhotos" id="myPhotos" alt="">

etc....

Unless I'm just totally way off track....
Copy linkTweet thisAlerts:
@fredmvJul 28.2004 — Two return values? Sure:function doSomething(a, b)
{
a += 1;
b += 2;
return { a: a, b: b };
}

var foo = doSomething(5, 5);
alert('1: ' + foo.a + 'n2: ' + foo.b);
Copy linkTweet thisAlerts:
@GerarDreamauthorJul 28.2004 — Thanks fredmv, this was what I was needing ?


@superdave77: Cuando quieras ? I have no place in my small home, but if you come to Buenos Aires, I can be your Cicerone ?

Thanks for the quick answer ?
Copy linkTweet thisAlerts:
@superdave77Jul 28.2004 — [i]Originally posted by fredmv [/i]

[B]Two return values? Sure:function doSomething(a, b)
{
a += 1;
b += 2;
return { a: a, b: b };
}

var foo = doSomething(5, 5);
alert('1: ' + foo.a + 'n2: ' + foo.b);
[/B][/QUOTE]


I guess I over-complicated that a bit......

lol

Muchas gracias, GerarDream. ¡Mucho gustaría!
×

Success!

Help @GerarDream spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...