0

Hi I am trying to call the namespace JavaScript which is given in the internal JavaScript in below HTML representation.

<head>
    <script type="text/javascript">
        var ns = {
            sampleAlert : function() {
                ns.message(var );
            }

            message :function(var ) {
                alert('msg');
            }
        }
    </script>
</head>

<body>
    <!--how to call the function sampleAlert-->
</body>

Is that possible? I am not able to call that namespace JavaScript function in the body.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555

2 Answers2

0

Call it like this:

ns.sampleAlert();

Read this link to have more understanding on JavaScript Namespace

Community
  • 1
  • 1
C.P.
  • 1,182
  • 3
  • 13
  • 32
0

You probably need to do something like the following.

<head>
    <script type="text/javascript">
        var ns = {
            sampleAlert : function(messageText) {
                ns.message(messageText);
            },

            message : function(text) {
                alert('msg ' + text);
            }
        }
    </script>
</head>

<body>
    <!--how to call the function sampleAlert-->
    <script type="text/javascript">
        ns.sampleAlert("this text will be displayed in the alert");
    </script>
</body>
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
ybot
  • 1
  • 3