468,248 Members | 1,470 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,248 developers. It's quick & easy.

conversion of java script variable in to php

sanjay123456
125 100+
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(this.form)">
</form>


<SCRIPT LANGUAGE="JavaScript">
function incr(form){
static var next_que=1;
next_que++;
document.writeln(next_que);
window.location.href = "http://localhost/abc.php?next_que=" +next_que;
}
</SCRIPT>


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


sanjay
Oct 27 '06 #1
9 2246
ronverdonk
4,258 Expert 4TB
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:
Oct 27 '06 #2
sanjay123456
125 100+
Sir

i am were try it but not work .

plz tell me solution

sanjay
Oct 28 '06 #3
ronverdonk
4,258 Expert 4TB
Your var cannot be declared static, so
Expand|Select|Wrap|Line Numbers
  1. var next_que=1;
  2.  
Ronald :cool:
Oct 28 '06 #4
sanjay123456
125 100+
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
Oct 28 '06 #5
sanjay123456
125 100+
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(this.form)">
</form>



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

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

?>

sanjay
Oct 28 '06 #6
ronverdonk
4,258 Expert 4TB
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:
Oct 28 '06 #7
sanjay123456
125 100+
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
Oct 29 '06 #8
ronverdonk
4,258 Expert 4TB
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($_SESSION['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><title>Questionnaire</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:
Oct 29 '06 #9
sanjay123456
125 100+
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
Oct 30 '06 #10

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

4 posts views Thread by Andy R. | last post: by
6 posts views Thread by Johan Louwers | last post: by
3 posts views Thread by StealthMonkey | last post: by
4 posts views Thread by Don Grover | last post: by
2 posts views Thread by ckerns | last post: by
31 posts views Thread by Bjørn Augestad | last post: by
9 posts views Thread by Stephen H. | last post: by
reply views Thread by NPC403 | last post: by
reply views Thread by kermitthefrogpy | last post: by
reply views Thread by zattat | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.