[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: High
  • Security: Public
  • Views: 45
  • Last Modified:

Global variable showing as undefined

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
peter-cooper
Asked:
peter-cooper
1 Solution
 
Nitin SontakkeDeveloperCommented:
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
 
peter-cooperAuthor Commented:
Thank you very much
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now