yasir faisal
yasir faisal

Reputation: 19

How to pass variable from one javascript file to other javascript file of different pages

I want to pass this usr_id from current javascript file to second javascript in which i have to use this id in the form to update.

delUser.addEventListener("click", function() {
		$("input:checkbox[name=u_id]:checked").each(function(){
		array_Online3.push($(this).val());});
		
	console.log(array_Online3[0]);
		//console.log();

	 usr_id=array_Online3[0];

I have used multiple solution like global vairable by accessing it with window.usr_id but its giving output as undefined.

document.getElementById("user_id").value=window.usr_id;
			var id=document.getElementById("user_id").value;

other solution is also not working

var globalVariable={
       usr_id: usr_id
	  
    };

document.getElementById("user_id").value=globalVariable.usr_id1;

Upvotes: 2

Views: 57

Answers (1)

agDev
agDev

Reputation: 865

Save it in localStorage like George Bailey suggested in the comment section.

// Store
localStorage.usrId = "Smith101";

// Retrieve
localStorage.usrId; //will return "Smith101"

//Remove
localStorage.removeItem("usrId");

Take a look here for more info on how localStorage works

Upvotes: 1

Related Questions