6 Replies - 952 Views - Last Post: 07 July 2010 - 01:57 AM Rate Topic: -----

#1 jasper199069  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 33
  • Joined: 19-August 08

while loop question

Posted 07 July 2010 - 01:20 AM

Hello people,

I am trying to let a while loop show one input box at the time and when i press the "enter" key it needs to show the next one.

any of you some ideas?

this is my code this far (just a simple while loop)

<?php

$a = 1;

while( $a != 11 )
{
	?>
	<form>
	<input type="text" value="<?php echo( $a ); ?>">
	</form>
	<?php
	$a++;
}



Thanks in advance,

Jasper

Is This A Good Question/Topic? 0
  • +

Replies To: while loop question

#2 no2pencil  Icon User is offline

  • Admiral Fancy Pants
  • member icon

Reputation: 5388
  • View blog
  • Posts: 27,384
  • Joined: 10-May 07

Re: while loop question

Posted 07 July 2010 - 01:22 AM

This would be better handled with Javascript. The PHP executes on the server, & the viewer will be clicking 'enter' on their web browser, so the PHP server will not see the keypresses in live time.
Was This Post Helpful? 0
  • +
  • -

#3 Valek  Icon User is offline

  • The Real Skynet
  • member icon

Reputation: 543
  • View blog
  • Posts: 1,713
  • Joined: 08-November 08

Re: while loop question

Posted 07 July 2010 - 01:23 AM

Basically what no2 said. Typically by the time the user sees the page and can press enter, PHP's already done executing.
Was This Post Helpful? 0
  • +
  • -

#4 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3576
  • View blog
  • Posts: 10,441
  • Joined: 08-June 10

Re: while loop question

Posted 07 July 2010 - 01:25 AM

if you want to react to the keypress event of the enter key, that’s not possible with PHP. PHP is a server side language, which doesn’t interact with the client besides HTTP requests.

you can of course submit the form each time and let PHP add one line/show another line.

you can also use Javascript (AJAX) to replace the value of the textbox.
Was This Post Helpful? 0
  • +
  • -

#5 jasper199069  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 33
  • Joined: 19-August 08

Re: while loop question

Posted 07 July 2010 - 01:28 AM

thanks for the replys so far but the keypress is not a problem ;)

the actual problem is that i want to show one input box at the time instead of them all at once

thanks in advance
Was This Post Helpful? 0
  • +
  • -

#6 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3576
  • View blog
  • Posts: 10,441
  • Joined: 08-June 10

Re: while loop question

Posted 07 July 2010 - 01:32 AM

then you must not use the while loop. rather store the current value of $a in a session variable and increment it at every request. abort if exceeding the limit.
Was This Post Helpful? 0
  • +
  • -

#7 jasper199069  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 33
  • Joined: 19-August 08

Re: while loop question

Posted 07 July 2010 - 01:57 AM

thanks of all the replys they where very helpful :)

for the rest i go to the javascript forum

thanks!! :D
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1