www.webdeveloper.com
Results 1 to 2 of 2

Thread: Exchanging values between two Java Scripts defined in two different files

  1. #1
    Join Date
    Jul 2014
    Posts
    1

    Exchanging values between two Java Scripts defined in two different files

    Hi,

    I have two Java scripts file say ''one.js'' and "two.js".

    There is a function in "one.js" named "setData()" that is defined below

    function setData(){
    sessionStorage.setItem("urldata", url);
    }

    Similarly, there is a function "getData()" given below defined in "two.js"

    function getData(){

    alert(sessionStorage.getItem("urldata"));

    }

    But by some how, I am unable to get value in getData(). It seems, sessionStorage.getItem("urldata") is not working. However, if I write getData() in the file "one.js" then it works.

    Please advise what is wrong with this code.

  2. #2
    Join Date
    Oct 2013
    Posts
    595
    This works:
    HTML Code:
    <!DOCTYPE html>
    <html>
    <head>
    	<meta charset="utf-8">
    	<title>sessionStorage</title>
    	<script src="one.js"></script>
    	<script src="two.js"></script>
    </head>
    <body>
    <div>
    
    	<input type="url" id="urlentry">
    	<input type="button" value="click first" onclick="setData(urlentry)">
    	<br>
    	<input type="button" value="click next" onclick="getData(urldisplay)">
    	<input type="url" id="urldisplay">
    
    </div>
    </body>
    </html>
    one.js:
    Code:
    function setData(u){
    	sessionStorage.url = u.value;
    }
    two.js:
    Code:
    function getData(d){
    	d.value = sessionStorage.url;
    }

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles