Jump to content

While Loop Drop-Down Form Field


sunziun

Recommended Posts

Hello everyone.There is a small problem with a drop-down form field I am trying to get work. I've this peace of code:

		<select name="pot">			<option value="0" selected="selected">1</option>				<?php for($p=0.12; $p<=5; $p++){ ?>					<option value="<?php echo $p ?>"></option>					<?php }  ?>		</select>

and what I get is this:

		<select name="pot">			<option value="0" selected="selected">1</option>									<option value="0.12"></option>										<option value="1.12"></option>										<option value="2.12"></option>										<option value="3.12"></option>										<option value="4.12"></option>							</select>

but it should be like this:

		<select name="pot">			<option value="0" selected="selected">1</option>									<option value="0.12">2</option>										<option value="0.24">3</option>										<option value="0.36">4</option>										<option value="0.48">5</option>										<option value="0.60">6</option>							</select>

please notice, first option is selected and it's value is 0.

  • Like 1
Link to comment
Share on other sites

i cant see any differences in first option, what i can see is the differences in rest of option tag values. is that the problem?<option value="0.24">3</option>

Edited by birbal
Link to comment
Share on other sites

Guest So Called
				<select name="pot">						<option value="0" selected="selected">1</option>								<?php for($p=1; $p<=5; $p++){ ?>										<option value="<?php echo $p*0.12; ?>"></option>										<?php }  ?>				</select>

You got your if statement improperly written.

Edited by So Called
Link to comment
Share on other sites

Thank you So Called and birbal, The suggestion of So Called was good! that was the hint I was looking for. It worked perfect and I've added the missing peace.I needed the first option to be 0 in the value and start from the second value with 0.12

<select name="pot"><option value="0" selected="selected">1</option><?php for($p=1; $p<=4; $p++){ ?><option value="<?php echo $p*0.12 ?>"><?php echo $p+1 ?></option><?php }  ?></select>

having done this I get what I wanted!

Edited by sunziun
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...