| | |
Why for loop in javascript is reseting a PHP variable
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Jun 2008
Posts: 21
Reputation:
Solved Threads: 0
Hi
I am in a bit of fix. I am developing a module in PHP where I am using javascripts to validate the data entered by the user. Now the problem is that I am firing a query to the database through PHP and hence storing its results in PHP variables. To validate a form I have to check whether the data entered by the user matches with database or not.
The above given code is written in tags of javascript. Now what's happening is that variable $ind is reseting itself when the loop starts again. At the end of loop if it's value is 1 then it becomes 0 when it reiterates the loop again.
What's going on guys. How could I retain the value of $ind
I am in a bit of fix. I am developing a module in PHP where I am using javascripts to validate the data entered by the user. Now the problem is that I am firing a query to the database through PHP and hence storing its results in PHP variables. To validate a form I have to check whether the data entered by the user matches with database or not.
PHP Syntax (Toggle Plain Text)
var i,x=0; <?php $ind=0; ?> for(i=0;i< <?php echo $num ?>;i++) { alert(<?php echo $ind; ?>); if(fobj.username.value== <?php echo "\"".$uname[$ind]."\"";?>) { alert(<?php echo "\"".$uname[$ind]."\"";?>); x=x+1; alert("if"); } alert("loop"); <?php $ind++; ?> alert(<?php echo $ind;?>); } if(x>=1) { alert("Can't login. User Name has expired."); return false; }
The above given code is written in tags of javascript. Now what's happening is that variable $ind is reseting itself when the loop starts again. At the end of loop if it's value is 1 then it becomes 0 when it reiterates the loop again.
What's going on guys. How could I retain the value of $ind
Commitment is what transforms a promise into reality. It is the words that speak boldly of your intentions. And the actions which speak louder than the words. It is making the time when there is none. Commitment is the stuff character is made of; the power to change the face of things. It is the daily triumph of integrity over skepticism.
![]() |
Other Threads in the PHP Forum
- Previous Thread: Running a script daily
- Next Thread: downloading an application from a site
Views: 750 | Replies: 1
| Thread Tools | Search this Thread |
Tag cloud for PHP
.htaccess access ajax apache api array autosuggest beginner binary broken cakephp checkbox class cms code cron curl database date directory display download dynamic echo email emptydisplayvalue error explodefunction file files folder form forms function functions google href htaccess html image include insert integration ip java javascript joomla jquery keywords limit link login loop mail menu methods mlm mod_rewrite multiple mysql oop parse paypal pdf php problem query radio random recursion regex remote script search searchbox select server sessions sms soap source space speed sql structure syntax system table tutorial update updates upload url validation validator variable video web xml youtube






