2

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;

2
  • 6
    why don't you store it in localStorage ? Commented Apr 19, 2018 at 19:04
  • If you are trying to access the data on actual "different pages" you can't store it in some variable, as that memory will be lost upon navigating to a different page. You would need to use other api like cookies, localStorage like George mentions, or passing as a url parameter Commented Apr 19, 2018 at 19:06

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.