conversion of java script variable in to php

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sanjay123456
    New Member
    • Sep 2006
    • 125

    conversion of java script variable in to php

    dear friends

    I want to convert a java script variable in to php varible

    some code i write its not work

    <form name="myform" method="post" action="abc.php ">
    <input type="button" name="next_que" VALUE="next" onClick="incr(t his.form)">
    </form>


    <SCRIPT LANGUAGE="JavaS cript">
    function incr(form){
    static var next_que=1;
    next_que++;
    document.writel n(next_que);
    window.location .href = "http://localhost/abc.php?next_qu e=" +next_que;
    }
    </SCRIPT>


    ?php
    echo "<h1>Screen Resolution:</h1>";
    echo "ghWidth : ".$_POST['next_que']."<br>";
    ?>


    sanjay
  • ronverdonk
    Recognized Expert Specialist
    • Jul 2006
    • 4259

    #2
    Before you post in this forum READ THE POSTING GUIDELINES. IN YOUR CASE ESPECIALLY THE USE OF TAGS AROUND YOUR CODE!!
    You post a GET variable in JS, so your code must be
    [php]echo "ghWidth : ".$_GET['next_que']."<br>";[/php]

    Ronald :cool:

    Comment

    • sanjay123456
      New Member
      • Sep 2006
      • 125

      #3
      Sir

      i am were try it but not work .

      plz tell me solution

      sanjay

      Comment

      • ronverdonk
        Recognized Expert Specialist
        • Jul 2006
        • 4259

        #4
        Your var cannot be declared static, so
        Code:
        var next_que=1;
        Ronald :cool:

        Comment

        • sanjay123456
          New Member
          • Sep 2006
          • 125

          #5
          Dear Sir,

          Thank you problem is solved .

          but java script have no STATIC AND CONSTANT VARIABLE
          then STATIC VAR next_que =1; statement not work.

          Is there r any other method that whenever onclick event is occure
          then next_que variable value is increment

          sanjay

          Comment

          • sanjay123456
            New Member
            • Sep 2006
            • 125

            #6
            Sir
            I think another way are following .......
            whenever we click next then next variable is increment by one
            but in this code some problem i am try to solve it .
            if anyone solve it then send on maling list.



            <form name="myform" method="post" action="abc.php ">
            <input type="button" VALUE="next" onClick="incr(t his.form)">
            </form>



            <SCRIPT LANGUAGE="JavaS cript">
            function incr(form){
            window.location .href = "http://localhost/abc.php";
            }
            </SCRIPT>

            <?php
            static $next=0;
            $next +=1;

            ?>

            sanjay

            Comment

            • ronverdonk
              Recognized Expert Specialist
              • Jul 2006
              • 4259

              #7
              I have no idea what you want to accomplish with this code. If the last part of your code (the PHP part) is the ABC.PHP then it won't work because you reload a fresh copy of ABC.PHP each time you call it from Javascript and each time the variable is declared and set to 1.

              Maybe there is another way, but explain what you want to accomplish with your code.

              And as I told you in the first reply: enclose your code within code or php or html tags. Read the Posting Guidelines before you post again!

              Ronald :cool:

              Comment

              • sanjay123456
                New Member
                • Sep 2006
                • 125

                #8
                Sir
                I want to make a online test paper .in this user click next button then
                new question will be come from database
                For this when ever onclick event is occure then php $next variable increment
                by one and next question will come from database

                sanjay

                Comment

                • ronverdonk
                  Recognized Expert Specialist
                  • Jul 2006
                  • 4259

                  #9
                  I explicitely requested you to read the Posting Guidelines before you post again.Now we see that you double posted this question in this same forum!! If you keep doing that, I will remove both posts. For now I removed the double post.

                  Here is an example of what you intend to accomplish. This sample does not use JavaScript because you'll have a problem when JS is turned off in the browser of the student. In this sample the number is stored in the count entry of the $_SESSION array, so it is available each time. Try it out and see what you can do with it. Good luck.
                  [php]<?php
                  session_start() ;
                  if (!isset($_SESSI ON['count']))
                  $_SESSION['count'] = 1;
                  if (isset($_POST['submitted'])) {
                  //
                  // Do the select of the question from database
                  // and the display of the question here
                  //
                  echo 'This is question no. '.$_SESSION['count'];
                  //
                  $_SESSION['count'] += 1;
                  }
                  ?>
                  <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
                  <html><head><ti tle>Questionnai re</title></head>
                  <body>
                  <form name="myform" method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>">
                  <input type="submit" VALUE="Click here for question <?php echo $_SESSION['count']; ?>" />
                  <input type="hidden" name="submitted " value="1" />
                  </form></body></html>[/php]
                  Ronald :cool:

                  Comment

                  • sanjay123456
                    New Member
                    • Sep 2006
                    • 125

                    #10
                    Sir
                    You send me following message

                    I explicitely requested you to read the Posting Guidelines before you post again.Now we see that you double posted this question in this same forum!! If you keep doing that, I will remove both posts. For now I removed the double post.



                    tell me sir that where i get editor where i wirte the code and mailing list


                    i dont understand




                    sanjay

                    Comment

                    Working...