Jump to content

While Loop Drop-Down Form Field

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 post
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 post
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 post
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 post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...