Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Is there a better way for this - options 2

Status
Not open for further replies.

ZOR

Technical User
Joined
Jan 30, 2002
Messages
2,963
Location
GB
I have about 40 items on an HTML page each having a selectable user entry of values between 0 and 5000. Results to be submitted. My dropdown box syntax is:
<option>0</option>
<option>10</option>
<option>20</option>
<option>30</option>
<option>40</option>
<option>50</option>
<option>60</option>
<option>70</option>
<option>80</option>
<option>90</option>
<option>100</option>
<option>110</option>
<option>120</option>

etc, etc. Ending up riduculous, any ideas, suggestions, thanks.
 
Something like this might work for you - insert it between the <select> and </select> tags:
Code:
<script type="text/javascript">
var count = 13;
var starting = 0;
var increment = 10;
for (var loop=starting; loop<=count; loop++) {
  document.write(' <option>' + parseInt(starting + (loop * increment),10) + '</option>');
}
</script>

You can then alter the variables to get different numbers... the example I show will produce the example you gave. I'm sure you can see how it works [smile]

Cheers,
Jeff

[tt]Jeff's Page @ Code Couch
[/tt]

What is Javascript? FAQ216-6094
 
just keep in mind, as you should with any javascript, that users with javascript disabled will not see any options.

if you're using any sort of server-side scripting (ASP, PHP, ColdFusion, etc.), that would definitely be the preferred method. If not, I'd stick with the way you're already doing it, to ensure all users are seeing what they're supposed to see.



*cLFlaVA
----------------------------
[tt]somebody set up us the bomb![bomb][/tt]

[URL unfurl="true"]http://www.coryarthus.com/[/url]
 
Many thanks Jeff, that works a treat. Thanks cLFlaVA, it does worry me about users having Java switched off getting nothing, I am using a server with PHP and MySql running. I did wonder about having a Units table but thought it wasteful. Thanks again.
 
you don't need to use a table. while this is the JS forum, I'll show you a php method:

Code:
for ( $i = 10; $i <= 120; $i += 10 ) {
    echo "<option value='" . $i . "'>" . $i . "</option>\n";
}



*cLFlaVA
----------------------------
[tt]somebody set up us the bomb![bomb][/tt]

[URL unfurl="true"]http://www.coryarthus.com/[/url]
 
Many thanks cLFlaVA for the php code, I will give that a try, and that removes the worry of java being off. Sorry for delay comming back, just saw it. I do have a second problem in that when a user returns to the page (reopened MySql database), how I return the combo to the originally set value, but also allowing him to change it. Was going to put it on php forum, but if you know would be appreciated. Thanks again.
 
Someone pulled a me.
[lol]

-kaht

Looking for a puppy?

silky-icon-left.gif
[small]Silky Terriers are small, relatively odorless dogs that shed no fur and make great indoor pets.[/small]
silky-icon-right.gif
 
j4606,

only difference is i first offered a JS solution, rather than begged for a star after supplying a non-forum-related solution.

;)

however, touché.

ZOR,

please post that question in the PHP forum - this way if another user has a similar question, they'll find the answer in the appropriate place.

thanks!



*cLFlaVA
----------------------------
[tt]somebody set up us the bomb![bomb][/tt]

[URL unfurl="true"]http://www.coryarthus.com/[/url]
 
Many thanks, I will post it on the PHP forum. Whats all the "Someone pulled a me"? If its about you getting a star, too bad, you earned it. Thanks anyway to the two people, you kept my thread at the top. When someone helps they deserve a star, just wish others took the time to thank people that way. See you on the other side for another star.
 
Thanks, and understood. We are all interconnected in languages, one does not exist without the other. Anyway looks good banter, all Tek-Tips forums are the best, and only made by people within them. Always greatful for help. Thought your Big Brother article interesting on Dell. Wonder if it's in my Inspiron, bit out of order if it is.
Regards
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top