0

I have made some calculation using jquery in Page1.html by getting the value from inputboxes using get function and store the variable tax6 and its value by setting in inputbox8 using set function of jquery. I have used window.location.href to pass the value of inputbox8 in variable tax7 in Page2.html. In Page2.html i have used document.url.indexof but i am not getting the value in inputbox9.

Page1.html

<!DOCTYPE html>
<html>
<body>

<p>Click the button to get a time-based greeting:</p>
INCOME: <input type="text" id="myinput" value="">
DEDUCTION: <input type="text" id="myinput1" value="" readonly>
GROSS INCOME: <input type="text" id="myinput2" value="" readonly>
TAX: <input type="text" id="myinput3" value=""readonly>
NET INCOME: <input type="text" id="myinput4" value="">

<button id="click1">CALCULATE NET INCOME</button><br><br>

NET INCOME: <input type="text" id="myinput5" value="">
AGRI INCOME: <input type="text" id="myinput6" value="">
OTHER SOURCE: <input type="text" id="myinput7" value="">
TOTAL INCOME: <input type="text" id="myinput8" value="">

<button id="click2">CALCULATE TOTAL INCOME</button>

<button id="click3">next</button>


<p id="demo"></p>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
    $("#click1").click(function a(){

        myfunction();

    });


function myfunction() {
var tax, tax1, tax2;
var inc = $("#myinput").val();
    alert(inc);
     $("#myinput1").val(10000);

     tax1 = inc - 10000;

     $("#myinput2").val(tax1);

        if (tax1 <=250000) {
        tax = "0";
     } 

    else if (tax1 >250000 && tax1<=500000) {
    tax = (tax1 - 250000)*5/100;
     }

    else if (tax1 >500000 && tax1<=1000000) {
    tax = 12000 + ((tax1 - 500000)*20/100);
     }

    else { tax = 112000 + ((tax1 - 1000000)*30/100);
     }

    $("#myinput3").val(tax);


    tax2 =  tax1 - tax;


    $("#myinput4").val(tax2);
    $("#myinput5").val(tax2);


}

 $("#click2").click(function b(){


        myfunction1();

    });
    function myfunction1() {
var tax4, tax5, tax6, tax7;
     var ni=$("#myinput4").val();


    var tax4 = $("#myinput6").val();
    var tax5 = $("#myinput7").val();


m=parseInt(ni); 
k=parseInt(tax4);
l=parseInt(tax5);
    tax6 = k + l+m;

    $("#myinput8").val(tax6);       

    $("#click3").click(function c(){
        window.location.href="getset-index2.html?tax7="+$('#myinput8').val();
    });

    }


});
</script>

</body>
</html>

Page2.html

<!DOCTYPE html>
<html>
<head>
<style>

</style>
</head>


<body>
TOTAL INCOME: <input type="text" id="myinput9" value="">
EMI HOUSE: <input type="text" id="myinput10" value="">
EMI CAR: <input type="text" id="myinput11" value="">
NET INCOME: <input type="text" id="myinput12" value="">

<button id="click4">CALCULATE NET INCOME</button><br><br>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>
$(document).ready(function(){

    $("#click4").click(function d(){


            myfunction2();
    });
        function myfunction2() {

var x, tax7, tax8, tax9;
var x = document.URL.indexof('?tax7=');
alert(x);
        $("#myinput9").val(x);

}
});
</script>
</body>
</html>
James Z
  • 12,209
  • 10
  • 24
  • 44
  • Possible duplicate of [Share data between html pages](https://stackoverflow.com/questions/11609376/share-data-between-html-pages) – Peter B Jan 07 '19 at 10:18
  • Possible duplicate of [How to get the value from the GET parameters?](https://stackoverflow.com/questions/979975/how-to-get-the-value-from-the-get-parameters) – Kaddath Jan 07 '19 at 10:39
  • indexOf function returns index (integer value) of the word that you have specified. – Sindhoor Jan 07 '19 at 11:05

1 Answers1

0

Use Below Function:

var getUrlParameter = function getUrlParameter(sParam) {
        var sPageURL = window.location.search.substring(1),
            sURLVariables = sPageURL.split('&'),
            sParameterName,
            i;

        for (i = 0; i < sURLVariables.length; i++) {
            sParameterName = sURLVariables[i].split('=');

            if (sParameterName[0] === sParam) {
                return sParameterName[1] === undefined ? true : decodeURIComponent(sParameterName[1]);
            }
        }
    };

and Call it As:

var x = getUrlParameter('tax7');
Sindhoor
  • 514
  • 3
  • 14