Results 1 to 3 of 3

Thread: Import from another page

  1. #1

    Thread Starter
    Lively Member k7l2010's Avatar
    Join Date
    Feb 2017
    Posts
    70

    Import from another page

    Hello
    Please Help
    Import a value from object a page

    index.htm
    HTML Code:
    <html dir="rtl">
    
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title></title>
    </head>
    <script>
    function myimport() {
    T2.value=T1.value//in page mm.htm;
     
     
    }
    
    </script>
    
    <body>
    <p align="center">
    
    
     
     <object   data="mm.htm" width="175" height="174"> 
     
    </object></p>
    
    
     
    
    
    <p align="center">
    
    
     
    
    
    <input type="text"  name="T2" size="20"></p>
    </p>
     
    
    
     
     
    
    
     
    
    
    <p align="center">
     
    
    
     
     
    
    
     
    
    
    <input type="button" name="go" id="bn" value="import" onclick="myimport()">
    </p>
    </p>
    </body>
    
    </html>



    mm.htm

    HTML Code:
    <html dir="rtl">
    
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title></title>
    </head>
    
    <body>
    <p align="center">
    <input type="text"  name="T1" size="20" value="OK"></p>
    </p>
    </body>
    
    </html>

  2. #2
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,711

    Re: Import from another page

    You could make a request to get the HTML of the separate web page, but there are some things to consider:
    1. If the separate web page exists on a different server, then you'll likely run into a cross-origin error
    2. If you expect the user to change the value on the separate web page, it wouldn't work unless you setup a JavaScript function to return the value


    To summarize, if you need the predefined value of T1 on the separate web page and the separate web page resides on the same web page that the requesting web page resides on then it would work.

    I'm not sure how it'd look in vanillla JavaScript, but in jQuery it'd look something like this:
    Code:
    function getInputValueFromSeparatePage(url, inputName) {
        $.get(url, function(result){
            const input = $(result).find(`input[name="${inputName}"]:first`);
            return input.val();
        });
    }
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

  3. #3

    Re: Import from another page

    With your scenario, I would solve by using localStorage.

    On page1:

    Code:
    window.onload = function() {
       var getInput = prompt("Hey type something here: ");
       localStorage.setItem("storageName",getInput);
    }
    On page2:

    Code:
    window.onload = alert(localStorage.getItem("storageName"));
    Hope it helps you!!

Posting Permissions

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



Click Here to Expand Forum to Full Width