How to return multiple value from Javascript ?


Hi

If you are working with java-script then you might be get scenario to return multiple value from function. Then we can return the multiple value like this code snippet as given below.

 


<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="MultipleValueReturn.aspx.cs" Inherits="JavaScriptTest.MultipleValueReturn" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script type="text/javascript">
        function test() {
            var no1 = 10;
            var no2 = 20;
            return {
                no1: no1,
                no2: no2
            };
        }

        function showAlertMsg() {
            var no3 = test().no1;
            alert(no3);
            var no4 = test().no2;
            alert(no4);
        }

    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <asp:Button ID="btnSubmit" runat="server" Text="Submit" OnClientClick="showAlertMsg();" />
    </div>
    </form>
</body>
</html>




Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.