Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Global variable showing as undefined

Posted on 2017-08-21
2
High Priority
?
37 Views
Last Modified: 2017-08-21
Hello
I am trying to declare a global javascript variable that I can use anywhere on the page. However, when I click on the button to open the action window it shows as 'undefined'.

I declared the variable in the head section like thus:
var ref;

Open in new window

I have posted my code and would be grteful if someone could help me correct this. Many thanks

// get the clicked row's data and initialize the input fields.
var dataRecord = $("#jqxgrid").jqxGrid('getrowdata', acteditrow);
activity = dataRecord.activity;
ref = dataRecord.item;
alert(ref); <--- THIS WORKS

if (activity == "New Intake") {
  $("#rack").val(dataRecord.rack);
  $("#row").val(dataRecord.row);
  $("#column").val(dataRecord.column);
  $("#bay").val(dataRecord.bay);
  $("#size").val(dataRecord.size);
  document.getElementById('destdate').value = dataRecord.destdate;

  // show the popup window.
  $("#actionWindow").jqxWindow('show');
}

Open in new window


HTML FURTHER DOWN THE PAGE SHOWING AS UNDEFINED IN THE ACTION WINDOW

<div>You are actioning item: <script type="text/javascript">ref</script></div>

Open in new window

0
Comment
Question by:peter-cooper
2 Comments
 
LVL 11

Accepted Solution

by:
Nitin Sontakke earned 3000 total points
ID: 42263127
Not sure if it can be done this way...never seen such code.

An alternative would be:

<div>You are actioning item: <div id='refContents'></div></div>

Open in new window


then in your javaScript code above add something as follows:

var refC = document.getElementById("refContents");
refC.innerText = ref;

Open in new window


Let me try to discourage you to use variable names like ref, which could have some meaning any language.
0
 

Author Closing Comment

by:peter-cooper
ID: 42263140
Thank you very much
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Find out what you should include to make the best professional email signature for your organization.
When crafting your “Why Us” page, there are a plethora of pitfalls to avoid. Follow these five tips, and you’ll be well on your way to creating an effective page.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Suggested Courses

926 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question