sunziun 1 Posted June 27, 2012 Report Share Posted June 27, 2012 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. 1 Quote Link to post Share on other sites
birbal 168 Posted June 27, 2012 Report Share Posted June 27, 2012 (edited) 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 June 27, 2012 by birbal Quote Link to post Share on other sites
Guest So Called Posted June 27, 2012 Report Share Posted June 27, 2012 (edited) <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 June 27, 2012 by So Called Quote Link to post Share on other sites
sunziun 1 Posted June 27, 2012 Author Report Share Posted June 27, 2012 (edited) 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 June 27, 2012 by sunziun Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.