| We hope you enjoy your visit. You're currently viewing our forum as a guest. This means you are limited to certain areas of the board and there are some features you can't use. If you join our community, you'll be able to access member-only sections, and use many member-only features such as customizing your profile, sending personal messages, and voting in polls. Registration is simple, fast, and completely free. Join our community! If you're already a member please log in to your account to access all of our features: |
- Pages:
- 1
- 2
| JavaScript: Changing a variables value based; on the selection in a drop-down list | |
|---|---|
| Tweet Topic Started: Jun 16 2005, 07:26 PM (1,278 Views) | |
| Postulate-ZNS | Jun 16 2005, 07:26 PM Post #1 |
|
I am, therefore I think: Descartes can shove it
![]() ![]() ![]() ![]() ![]() ![]() ![]()
|
For example, if you had a variable:
...and a drop down list containing two selections: "6" and "7." Selecting "6" would change the variable's value to 6, while selecting "7" would change it to 7. I hope you see what I mean. Any help would be greatly appreciated.
|
![]() |
|
| Stefan | Jun 16 2005, 07:34 PM Post #2 |
![]()
Mew?
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]()
|
That's pretty much it.
|
![]() |
|
| Postulate-ZNS | Jun 16 2005, 07:37 PM Post #3 |
|
I am, therefore I think: Descartes can shove it
![]() ![]() ![]() ![]() ![]() ![]() ![]()
|
Ah, thanks a bunch. ![]() EDIT: Oh, and one more quick related question, while we're on the subject, for anyone who may know: is it possible to change multiple variables with one selection by repeating the code or adding to it? Thanks!
|
![]() |
|
| JoeC | Jun 16 2005, 08:01 PM Post #4 |
|
Euch! IE tastes horrible!
![]() ![]() ![]() ![]() ![]() ![]() ![]()
|
Yes.
|
![]() |
|
| Postulate-ZNS | Jun 16 2005, 08:35 PM Post #5 |
|
I am, therefore I think: Descartes can shove it
![]() ![]() ![]() ![]() ![]() ![]() ![]()
|
Thank you. ![]() EDIT: Forgive me for being an idiot, but...
What exactly am I supposed to replace "this.options" and "this.selectedIndex" with? :unsure: |
![]() |
|
| Stefan | Jun 17 2005, 06:57 AM Post #6 |
![]()
Mew?
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]()
|
The only thing you would have to replace is someVariable, with your variable name. The this in this.options and this.selectedIndex refers to the dropdown itself. options refers to its options and selectedIndex refers to the currently selected item. |
![]() |
|
| Postulate-ZNS | Jun 17 2005, 12:22 PM Post #7 |
|
I am, therefore I think: Descartes can shove it
![]() ![]() ![]() ![]() ![]() ![]() ![]()
|
This is how I have it set up:
And it isn't working :unsure: I have the variable displayed below, and it doesn't change with selection. Sorry for all the questions. >_< |
![]() |
|
| Gornakle | Jun 17 2005, 01:33 PM Post #8 |
|
Member
![]() ![]() ![]() ![]() ![]() ![]() ![]()
|
How did you display it? If you simply document.write()ed it, it's static. It's written to the screen once and won't update when the variable changes. |
![]() |
|
| Postulate-ZNS | Jun 18 2005, 01:26 AM Post #9 |
|
I am, therefore I think: Descartes can shove it
![]() ![]() ![]() ![]() ![]() ![]() ![]()
|
I have it displayed in a text field, with a "document.forms...etc." JavaScript block at the end of the document to insert the variable in a text field. Will it still remain static? And if so, is there any other way to change the value of a text filed based on a select list option? :unsure: |
![]() |
|
| Postulate-ZNS | Jun 20 2005, 12:47 PM Post #10 |
|
I am, therefore I think: Descartes can shove it
![]() ![]() ![]() ![]() ![]() ![]() ![]()
|
I hate to bump this, but i would like an answer. It's not too urgent, but I do have to finish this script soon. Thanks to Stefan, Gornakle, and JoeC for helping me previously.
|
![]() |
|
| solinent | Jun 23 2005, 12:01 PM Post #11 |
|
Member
![]() ![]() ![]() ![]() ![]()
|
I've tested this one. Allways use variable names that aren't really that normal, because the name variable is probably not allowed ![]() here:
|
![]() |
|
| Postulate-ZNS | Jun 23 2005, 12:21 PM Post #12 |
|
I am, therefore I think: Descartes can shove it
![]() ![]() ![]() ![]() ![]() ![]() ![]()
|
Thanks a lot, I'll be sure to try it out!
|
![]() |
|
| Postulate-ZNS | Jun 29 2005, 02:48 PM Post #13 |
|
I am, therefore I think: Descartes can shove it
![]() ![]() ![]() ![]() ![]() ![]() ![]()
|
I got it to work perfectly, but another issue arises: is it possible to have two variables changed by selecting an option that shows in two text fields? So, if I have two text input areas in a form, can it be made so that a different value shows in each one (i.e., one that says "3" and another that says "4") by selecting just one option? Again, thanks so much for your help!
|
![]() |
|
| solinent | Jun 29 2005, 08:57 PM Post #14 |
|
Member
![]() ![]() ![]() ![]() ![]()
|
Should work:(I'm not sure that's what you mean but...)
|
![]() |
|
| Postulate-ZNS | Jun 30 2005, 12:39 AM Post #15 |
|
I am, therefore I think: Descartes can shove it
![]() ![]() ![]() ![]() ![]() ![]() ![]()
|
Thank you for your input, I'll try this out. If it doesn't work, I'll be sure to explain myself more clearly if you're still in the mood to help out. ![]() EDIT: Not quite what I'm looking for, but oh so close. What I want is so that based on which selection in the drop-down is made, two different fields show two different specific numbers (sorry, I didn't make that clear). The numbers have no relation to each other; they have to be clearly defined. Is this possible? (If you need more of an explanation, please ask, as sometimes I have difficulty explaining myself clearly). Thank you so much! |
![]() |
|
| 1 user reading this topic (1 Guest and 0 Anonymous) | |
| Go to Next Page | |
| « Previous Topic · Technology Chat · Next Topic » |
- Pages:
- 1
- 2
| Track Topic · E-mail Topic |
9:10 AM Jul 11
|



![]](../../../../0/1/0/p601690/pipright.png)






9:10 AM Jul 11