• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

assigning a function's result to a form field

 
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

I have this js code:


so... i need to pass the selected option to a form, but it doesn;t work like i did it. While alert(elementValue) is printing the correct thing
alert('segment '+ searchForm.segment.value); print just segment. So... what is going on?

Thanks.
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You are not making sense here.

You are setting the value of a dropdown that you already knwo the text of?

Also segment here [searchForm.segment.value] is looking for a name and not an id.

Eric
 
Nick Potter
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No, i have a drop-down menu. The user selects an option and i want to get that option (the text of the option, not the value) in order to submit it to the server.
Yes, searchForm.segment.value is looking for a name and it's present. I have more fields and this works with the exception of the select element.
 
Eric Pascarello
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
well if you have one element with an id and one element with a name and they are the same value, you may be having a naming collision. Rename one of the elements.

Eric
 
Nick Potter
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Nope, checked it, no name collision.
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

No, i have a drop-down menu. The user selects an option and i want to get that option (the text of the option, not the value) in order to submit it to the server.


Why are you making it hard on yourself? As it is the value that gets submitted to the server, just make that what you want submitted.
 
Nick Potter
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Because i don't have a submit, but a button. I need it to pass the input params to validation functions etc. So... how do i submit what option is selected in javascript if not using the selectedIndex?
 
Eric Pascarello
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is searchForm.segment a hidden element, a textbox?

Eric
 
Nick Potter
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A select

 
Eric Pascarello
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How are you setting the value of the select without selecting the item?

Setting the value in JavaScript will do is try to select the value. You basically would need what you do to read the text. I am not sure why you are not just setting the values when you are creating the option to begin with.

Eric
 
Nick Potter
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm not sure i get what you want to say. Let me try... you mean i should write something like that:
? and get it in javascript with
?

If so... what if i have different things for value and text? How do i get the text from it?
 
Eric Pascarello
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Shouldn't you be able to get that on the server?

If you want to submit the text along with it, than you need to set a hidden field with the value. That is what I thought you were doing from the start.

Or change your notation for the select value to be a way to get both sets of data. something like value="value::text" and on the server you do your magic.

Eric
 
catch it before it slithers away! Oh wait, it's a tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic