Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Global variable showing as undefined

Posted on 2017-08-21
2
High Priority
?
27 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 10

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
Without even knowing it, most of us are using web applications on a daily basis.  In fact, Gmail and Yahoo email, Twitter, Facebook, and eBay are used by most of us daily—and they are web applications. We generally confuse these web applications to…
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…
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…

705 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