Results 1 to 7 of 7

Thread: Select Element Question

  1. #1

    Thread Starter
    Frenzied Member TheBionicOrange's Avatar
    Join Date
    Apr 2001
    Location
    Cardiff, UK
    Posts
    1,818

    Question Select Element Question

    I'm using a select element on my html page.

    Lets say its called cboPriority.

    How do I move the value of this element into a temporary field ? I want to store the text that is displayed on screen for the user, not the index number or anything like that.

    I tried using the 'VALUE' attribute, but that always appears empty.


    TIA.

  2. #2
    Lively Member
    Join Date
    May 2001
    Location
    Falkenberg, Sweden
    Posts
    76
    Ok, so you want to move the text from a select-box to another field?
    Code:
    <html><body>
    <form name="frm">
    <select name="sel">
    <option value="1">VB</option>
    <option value="2">ASP</option>
    </select>
    <br>
    <input type="button" onClick="document.frm.txtVal.value=document.frm.sel[document.frm.sel.selectedIndex].text">
    <input type="text" name="txtVal">
    </form></body></html>
    When you click the button, the text from the select-box will be displayed in the text-box. This can easily be built within a js-function.
    ________________________
    Fredrik Klarqvist

  3. #3

    Thread Starter
    Frenzied Member TheBionicOrange's Avatar
    Join Date
    Apr 2001
    Location
    Cardiff, UK
    Posts
    1,818

    Not Quite ...

    I'm using VB script, so is it possible you could tell me what the equivalent of that HTML code is ?


    I'm only trying to store the value in a temporary variable. It will be used to update a database field later on.

  4. #4
    Lively Member
    Join Date
    May 2001
    Location
    Falkenberg, Sweden
    Posts
    76
    Hello, the code translated to VBScript is almost the same:
    Code:
    <html>
    <body>
    <script language=VBSCRIPT>
    sub getText(objItm)
    	dim strVal
    	strVal =  objItm(objItm.selectedIndex).text
    	msgbox "The value is: " &strVal
    end sub
    </script>
    <form name="frm">
    <select name="sel">
    <option value="1">VB</option>
    <option value="2">ASP</option>
    </select>
    <br>
    <input type="button" onClick="getText(document.frm.sel)" value="click me">
    </form>
    </body>
    </html>
    That should do it!
    ________________________
    Fredrik Klarqvist

  5. #5

    Thread Starter
    Frenzied Member TheBionicOrange's Avatar
    Join Date
    Apr 2001
    Location
    Cardiff, UK
    Posts
    1,818
    hanks for all your help Fredrick, but I don't think I am explaining myself very well.

    I am using VB6, not HTML script, for this project. My HTML page is designed using the VB6 DHTML Page Designer (which is pretty rubbish I know !). I have physical VB code attached to my ActiveX objects.

    Therefore I am trying something alonng the lines of :

    *****************************************
    Private Sub cboNeworMod_onchange()
    NeworMod = cboNeworMod.Value

    End Sub
    *****************************************

    The problem with this is that .VALUE returns an empty string, which is less than ideal.

    The user has 2 possible choices:- "New" or "Modification".

    If they click on screen and change it then I want to store "New" or "Modification", depending on which one they clicked.

    Later on this text will update a field on a database record that will be created.


    I hope that makes more sense, and thanks very much for the help so far. I appreciate I could make my life a lot easier if I brushed up on HTML, but at the moment I don't have the time !

  6. #6
    Lively Member
    Join Date
    May 2001
    Location
    Falkenberg, Sweden
    Posts
    76
    ok, I give it try again...

    Code:
    Private Sub sel_onchange()
        strVal = sel.Item(sel.selectedIndex).Text
        MsgBox strVal
    End Sub
    I've tried this myself from VB and it works fine. (sel is the name of the select-box).

    I hope this will do it!
    ________________________
    Fredrik Klarqvist

  7. #7

    Thread Starter
    Frenzied Member TheBionicOrange's Avatar
    Join Date
    Apr 2001
    Location
    Cardiff, UK
    Posts
    1,818

    Cool Thank You.

    Thanks Fredrick.

    That is exactly what I needed and it now works perfectly.

    Thanks a lot for all your help.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width