sunziun Posted June 27, 2012 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 Link to comment Share on other sites More sharing options...
birbal Posted June 27, 2012 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 Link to comment Share on other sites More sharing options...
Guest So Called Posted June 27, 2012 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 Link to comment Share on other sites More sharing options...
sunziun Posted June 27, 2012 Author 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 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now