0

I have a page which have few images. checking images will add to score. it works fine with below code and score is displayed on page. Now i want a button "My score" to open a new window and display score there. Currently it gives a blank page. Please provide code for result.html and if my current code need some changes.

<html>

    <head>
        <meta content="text/html; charset=UTF-8" http-equiv="content-type">
        <title></title>
                            <script type="text/javascript" src="http://code.jquery.com/jquery-1.7.2.js" ></script>

 <!--*****************************************************script to count checked items Actor/Actress begin**************************************-->
<script type='text/javascript'>//<![CDATA[ 
$(window).load(function(){
    var actor=0;
    $(document).ready(function() {
        $('#perk1').html(actor);

        $("#img100").click(function() {
            if($('#img100').is(':checked'))
                actor=actor+1;
            else if(actor>0)
                actor=actor-1;
            $('#perk1').html(actor);
        });

        $("#img95").click(function() {
            if($('#img95').is(':checked'))
                actor=actor+1;
            else if(actor>0)
                actor=actor-1;
            $('#perk1').html(actor);
        });

    });


});//]]>  

</script>
 <!--******************************script to count checked items actor ends***************************************************************-->  
<!--******************************script to save count actor begins***************************************************************--> 
<script>
function myFunction()
{
window.open("result.html","","width=700,height=150,top=300,left=300");
}
</script>
 <!--******************************script to save count actor ends***************************************************************-->
     </head>

<!--************************************************************************body begins*************************************************************-->
  <body Body Params>
<!--*******************value of actor checked clicked here begins***************************************************-->
movies you have watched: <span id="perk1"></span></br>




<!--*******************value of actor checked clicked here ends***************************************************-->
<!--**********************************************Code to share result begins*************************************************************-->
<button onclick="myFunction()">My score</button>



<!--**********************************************Code to share result begins*************************************************************-->
</br>
Please check the movies you have watched
<!--********************************************actor movies begin************************************************************************-->
<div class="imgs">

<div class="thumb">
<label for="img100"><img src="priyanka_chopra\gunday.jpg" height="200" width="275"/></label>
<input type="checkbox" class="chk " id="img100" name="img100" value="0" />
<label for="img95"><img src="priyanka_chopra\krrish3.jpg" height="200" width="275"/></label>
<input type="checkbox" class="chk " id="img95" name="img95" value="0" />

</div>
</div>
<!--********************************************actor movies end************************************************************************-->
  </div>
<!--******************************************actor code ends***************************************************************************-->


</body>

<!--************************************************************************body ends*************************************************************-->



</html>
Saurabh Shrivastava
  • 1,394
  • 4
  • 21
  • 50

3 Answers3

0

You can store score variable in hidden fields and get the hidden fields value in new page or window.

0

Updated:

You also pass your variable as URL :

Like :

In Main Page :

window.open("result.html?score="+actor,"","width=700,height=150,top=300,left=300");

And get Score using :

In Result.html

function geturlvar() {
    var vars = {};
    var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi,             function(m,key,value) {
    vars[key] = value;
   });
   return vars;
 }

Use to get URL Variable :

 var score = geturlvar()['score'];

Example

May this helps you..

ashbuilds
  • 1,401
  • 16
  • 33
0

You could pass it via a query string.

<button id="submitButton">My score</button>

$(function () {
var actor = 0;
$(document).ready(function () {
    $('#perk1').html(actor);

    $("#img100").click(function () {
        if ($('#img100').is(':checked')) actor = actor + 1;
        else if (actor > 0) actor = actor - 1;
        $('#perk1').html(actor);
    });

    $("#img95").click(function () {
        if ($('#img95').is(':checked')) actor = actor + 1;
        else if (actor > 0) actor = actor - 1;
        $('#perk1').html(actor);
    });

    $("#submitButton").on("click", function () {
        alert(actor);
        var url = "result.html?val=" + actor;
        window.open(url, "", "width=700,height=150,top=300,left=300");
    });

});
}); //]]>

Then on the results.html page, you would grab the value from the query string similar to what is shown here; https://stackoverflow.com/a/901144/173949

Community
  • 1
  • 1
Ryan Anderson
  • 937
  • 10
  • 23