How do I get a form list "value", not the "text?

  • I have some form List controls. They have items with "values" (database _id's) as well as "text". It's clear how to get the text but how do I get the _id's stored in the item values?

  • There is nothing can stop you from using int() function.

    a = 0 //numeric var
    s = '5552368' //string var
    a = int(s); // a = 5552368
    
    beware: 
    a = 100
    s = 'text'
    a = int(s) // a = 0
    [/code:28jf9ltq]
    
    And now I read your question more attentively.. I understand, you want an Index of selected item in List plugin? It is [i]List.SelectedIndex[/i] expression.
  • No, I want to get the "value" in the "Select" control on the form. In the Html the select control looks like...

    <select>
    <option value="someDbaseId">Marks name text</option>
    </select>
    [/code:2f7gb3gy]
    
    I can see in C2 List control how to get the text of the option (item), but not the value. Follow?
  • Sorry, man.. I don't even know how to do what you knows..

  • Sorry, man.. I don't even know how to do what you knows..

    No problem

    I've hacked around the issue with a couple functions wrapping an array. However I'd greatly prefer using a built in solution

  • So other than my hack mentioned above, this isn't possible in C2?

  • You can get form control List "Text" values easily but there is no C2 built-in way to get a List "Value"?!?

    So... this is a feature or omission?

  • I think C2 just uses the index and not a value for the list items.

    Looks like best you can do is get the index number of a selected text.

    The work around would be to have the values associated with the list items stored and referenced to from somewhere else. (local vars, globals, instance vars)

    You could even use the instance vars from the list itself.

  • Right now I have some functions that I use to set the Text attribs in the Lists objects and at the same time set an associated Value in an array. It's pretty amazing that there isn't a built in way to get the List.SelectedItemValue too. I'd love to know why not

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Its likely an easy addition to the existing code, you could request for it perhaps.

    Perhaps it has to do with that a lot of web developers use the text as value.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)