如何将html输入正确保存到会话变量中

时间:2018-11-28 14:24:21

标签: javascript paypal

我一直在存储客户详细信息,如果他们从结帐页面重定向了客户详细信息,他们已经将其输入到会话变量中,这些变量将应用于相关的html框。这是由于Paypal错误(我在此工作的地方,因为这个奇怪的Paypal设置(输入所有信息后的最后一步)而实施的)。该修复程序似乎已经工作了一段时间,但是现在显然在过去的几周中,人们已经从Paypal重定向回去,其相关框现在为空。

下面是我用来存储会话变量的脚本。

<script>
   // Run on page load
      window.onload = function() {

       // If sessionStorage is storing default values (ex. name), exit the function and do not restore data
       if (sessionStorage.getItem('billing_firstname') == "billing_firstname") {
           return;
       }

       // If values are not blank, restore them to the fields
       var billing_firstname = sessionStorage.getItem('billing_firstname');
       if (billing_firstname !== null) $('#billing_firstname').val(billing_firstname);

         var billing_lastname= sessionStorage.getItem('billing_lastname');
       if (billing_lastname !== null) $('#billing_lastname').val(billing_lastname);

         var billing_company= sessionStorage.getItem('billing_company');
       if (billing_company !== null) $('#billing_company').val(billing_company);


       var billing_state= sessionStorage.getItem('billing_state');
       if (billing_state !== null) $('#billing_state').val(billing_state);

       var billing_country= sessionStorage.getItem('billing_country');
       if (billing_country !== null) $('#billing_country').val(billing_country);

       var billing_address= sessionStorage.getItem('billing_address');
       if (billing_address !== null) $('#billing_address').val(billing_address);

       var billing_address2= sessionStorage.getItem('billing_address2');
       if (billing_address2 !== null) $('#billing_address2').val(billing_address2);

       var billing_city= sessionStorage.getItem('billing_city');
       if (billing_city !== null) $('#billing_city').val(billing_city);

       var billing_zip= sessionStorage.getItem('billing_zip');
       if (billing_zip !== null) $('#billing_zip').val(billing_zip);

       var billing_phone= sessionStorage.getItem('billing_phone');
       if (billing_phone !== null) $('#billing_phone').val(billing_phone);




   }

   // Before refreshing the page, save the form data to sessionStorage
    window.onbeforeunload = function() {
       sessionStorage.setItem("billing_firstname", $('#billing_firstname').val());
       sessionStorage.setItem("billing_lastname",$('#billing_lastname').val());
       sessionStorage.setItem("billing_company",$('#billing_company').val());
       sessionStorage.setItem("billing_state", $('#billing_state').val());
       sessionStorage.setItem("billing_country", $('#billing_country').val());
       sessionStorage.setItem("billing_address",$('#billing_address').val());
       sessionStorage.setItem("billing_address2",$('#billing_address2').val())
       sessionStorage.setItem("billing_city",$('#billing_city').val());
       sessionStorage.setItem("billing_zip",$('#billing_zip').val());
       sessionStorage.setItem("billing_phone",$('#billing_phone').val());

   }
</script>

<script>
   // Run on page load
      window.onload = function() {

       // If sessionStorage is storing default values (ex. name), exit the function and do not restore data
       if (sessionStorage.getItem('shipping_firstname') == "shipping_firstname") {
           return;
       }

       // If values are not blank, restore them to the fields
       var shipping_firstname = sessionStorage.getItem('shipping_firstname');
       if (shipping_firstname !== null) $('#shipping_firstname').val(shipping_firstname);

         var shipping_lastname= sessionStorage.getItem('shipping_lastname');
       if (shipping_lastname !== null) $('#shipping_lastname').val(shipping_lastname);

         var shipping_company= sessionStorage.getItem('shipping_company');
       if (shipping_company !== null) $('#shipping_company').val(shipping_company);


       var shipping_state= sessionStorage.getItem('shipping_state');
       if (shipping_state !== null) $('#shipping_state').val(shipping_state);

       var shipping_country= sessionStorage.getItem('shipping_country');
       if (shipping_country !== null) $('#shipping_country').val(shipping_country);

       var shipping_address= sessionStorage.getItem('shipping_address');
       if (shipping_address !== null) $('#shipping_address').val(shipping_address);

       var shipping_address2= sessionStorage.getItem('shipping_address2');
       if (shipping_address2 !== null) $('#shipping_address2').val(shipping_address2);

       var shipping_city= sessionStorage.getItem('shipping_city');
       if (shipping_city !== null) $('#shipping_city').val(shipping_city);

       var shipping_zip= sessionStorage.getItem('shipping_zip');
       if (shipping_zip !== null) $('#shipping_zip').val(shipping_zip);

       var shipping_phone= sessionStorage.getItem('shipping_phone');
       if (shipping_phone !== null) $('#shipping_phone').val(shipping_phone);


          //Billing

        // If values are not blank, restore them to the fields
       var billing_firstname = sessionStorage.getItem('billing_firstname');
       if (billing_firstname !== null) $('#billing_firstname').val(billing_firstname);

         var billing_lastname= sessionStorage.getItem('billing_lastname');
       if (billing_lastname !== null) $('#billing_lastname').val(billing_lastname);

         var billing_company= sessionStorage.getItem('billing_company');
       if (billing_company !== null) $('#billing_company').val(billing_company);


       var billing_state= sessionStorage.getItem('billing_state');
       if (billing_state !== null) $('#billing_state').val(billing_state);

       var billing_country= sessionStorage.getItem('billing_country');
       if (billing_country !== null) $('#billing_country').val(billing_country);

       var billing_address= sessionStorage.getItem('billing_address');
       if (billing_address !== null) $('#billing_address').val(billing_address);

       var billing_address2= sessionStorage.getItem('billing_address2');
       if (billing_address2 !== null) $('#billing_address2').val(billing_address2);

       var billing_city= sessionStorage.getItem('billing_city');
       if (billing_city !== null) $('#billing_city').val(billing_city);

       var billing_zip= sessionStorage.getItem('billing_zip');
       if (billing_zip !== null) $('#billing_zip').val(billing_zip);

       var billing_phone= sessionStorage.getItem('billing_phone');
       if (billing_phone !== null) $('#billing_phone').val(billing_phone);




   }

   // Before refreshing the page, save the form data to sessionStorage
    window.onbeforeunload = function() {
       sessionStorage.setItem("shipping_firstname", $('#shipping_firstname').val());
       sessionStorage.setItem("shipping_lastname",$('#shipping_lastname').val());
       sessionStorage.setItem("shipping_company",$('#shipping_company').val());
       sessionStorage.setItem("shipping_state", $('#shipping_state').val());
       sessionStorage.setItem("shipping_country", $('#shipping_country').val());
       sessionStorage.setItem("shipping_address",$('#shipping_address').val());
       sessionStorage.setItem("shipping_address2",$('#shipping_address2').val())
       sessionStorage.setItem("shipping_city",$('#shipping_city').val());
       sessionStorage.setItem("shipping_zip",$('#shipping_zip').val());
       sessionStorage.setItem("shipping_phone",$('#shipping_phone').val());

        //billing

         sessionStorage.setItem("billing_firstname", $('#billing_firstname').val());
       sessionStorage.setItem("billing_lastname",$('#billing_lastname').val());
       sessionStorage.setItem("billing_company",$('#billing_company').val());
       sessionStorage.setItem("billing_state", $('#billing_state').val());
       sessionStorage.setItem("billing_country", $('#billing_country').val());
       sessionStorage.setItem("billing_address",$('#billing_address').val());
       sessionStorage.setItem("billing_address2",$('#billing_address2').val())
       sessionStorage.setItem("billing_city",$('#billing_city').val());
       sessionStorage.setItem("billing_zip",$('#billing_zip').val());
       sessionStorage.setItem("billing_phone",$('#billing_phone').val());

   }
</script>

0 个答案:

没有答案