Solution 1 :

You could accomplish that in a few ways.

  1. add the value to the redirect url.
  2. save the value in a cookie
  3. save the value in a server side session
  4. save the value client side in local storage

Solution 2 :

You can make use of client side localStorage or sessionStorage

in page 1,

<input type="text" id="1" value="">
<button onclick="save();">Save now</button>

in your javascript file, put this:

function save(){
var inputValue=$('#1').val();
sessionStorage.setItem('save', inputValue);
location.href='link to second page'
}

//In page two, you can do whatever you want with the saved value, in js file

alert( sessionStorage.getItem('save') );

Solution 3 :

you can do this thing by using the js local storage here below is code in jquery and javascript, both will work charm

Pure Javascript

 <input type="text" id="localstore">
 <button onclick="savelocal()">Save</button>
<script>
  document.getElementById("localstore").value = localStorage.getItem("inputval");
    function savelocal(){
        var loc = document.getElementById("localstore").value;
        localStorage.setItem("inputval", loc);
        window.location.href = "http://yourpath/page2";
    }
</script>

with Jquery

<input type="text" id="localstore">
<button class="saveto">Save</button>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>

<script>
 $('#localstore').val(localStorage.content);
    $('.saveto').on('click', function(){
        localStorage.content = $('#localstore').val();
        window.location.href = "http://yourpath/page2";
    })
</script>

Problem :

I have 2 webpages. They both have on them.

User starts on Page1. If user types “cat” into Page1 input box, I want user to be redirected to Page2 with ‘cat’ automatically filled out in Page2 input box.

Possible at all with jQuery/JavaScript? I’m guessing no, but thought I would ask.

By

Leave a Reply

Your email address will not be published. Required fields are marked *