Page 1 of 1

HTML field not updated

Posted: 02 Mar 2016
by Helge
Hi

I am creating a HTML script but can't find a way to define a global variable that works in and outside of my procedures, any suggestions?

Second question, since I can't manage to define a global variable I tought that I could use a html text field named "TaskId" as a workaround.

using the logic below, but altough the field is updated the IF function does not work before i enter the script again - its not updated while I am "in" the script?


$('#TaskId').attr('value', 'fant');

if (document.getElementById("TaskId").value=="fant") {alert("fant");} else {alert("fant ikke");}

Re: HTML field not updated

Posted: 03 Mar 2016
by rostislav
1. To make a variable global you can assign it to the global object, which is, in case of browsers, window:

Code: Select all

var myvar = "my variable";

window.myvar = myvar; 
2. You are setting the 'value' attribute of the input element, not the content of the box. Try this:

Code: Select all

$('#TaskId').val('fant');

if (document.getElementById("TaskId").value=="fant") {

 alert("fant");

} else {

 alert("fant ikke");
 }