-1

I'm using a gup function in my html file:

HTML

<div id="selectPort">
    <label id="msgForNonICD">
        Select a port to view its ICD details
    </label>
</div>
<script src='dojoroot/dojo/dojo.js'></script>

JavaScript

var nodeLabel = gup('nodeLabel');
console.log("printing nodeLabel"+nodeLabel);

This throws an error: gup not defined. How should I go about defining this function?

royhowie
  • 10,605
  • 14
  • 45
  • 66
user3271040
  • 39
  • 1
  • 1
  • 8
  • Related question on different ways to define JavaScript functions: http://stackoverflow.com/questions/336859/var-functionname-function-vs-function-functionname – Casey Falk Jul 16 '14 at 13:26

2 Answers2

3

I'm getting gup not defined

The most obvious reason reason why you are getting this error is that you missed to define your gup function.

You probably want to define it and resolve your error:

function gup(string) {
//your logic here
}
Rahul Tripathi
  • 152,732
  • 28
  • 233
  • 299
0

I don't know what a "gup" function is. I'm going to assume that you're talking about a "Get URL Parameter" function here, possibly like the one defined here. If I'm wrong about what it does, then you can still adapt this answer to whatever function you need.

I see that you're trying to use the Dojo toolkit. But Dojo has no "gup" function, and vanilla JavaScript doesn't have one either, so you'll need to define it yourself. Paste the code for your function (or write it out) into a file, and then reference it using another <script> tag in your HTML. If the JavaScript file is in the same directory as your HTML file, then the result might look like this:

In gup.js:

// This code is based on the snipplr referenced in this answer
var gup = function(name) {
    var results = (
        new RegExp("[\\?&]"+name+"=([^&#]*)")
    ).exec(window.location.href);

    if (results == null) {
        return "";
    } else {
        return results[1];
    }
};

In index.html:

<!DOCTYPE html>
<html>
<body>
<div id="selectPort"><label id="msgForNonICD">Select a port to view its ICD details</div>
<script src='gup.js'></script>
<script src='dojoroot/dojo/dojo.js'></script>
<script type="text/javascript">
var nodeLabel = gup('nodeLabel');
console.log("printing nodeLabel"+nodeLabel);
</script>
</body>
</html>
The Spooniest
  • 2,713
  • 12
  • 14