Results 1 to 13 of 13

Thread: Adding elements to SELECT with VBScript ?

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Oct 2000
    Location
    Québec, Canada
    Posts
    212

    Adding elements to SELECT with VBScript ?

    How can I add elements to SELECT with VBScript ?

    Thanks !
    Regards,

    El-Nino

  2. #2
    Black Cat JoshT's Avatar
    Join Date
    Nov 2000
    Location
    WNY, USA
    Posts
    4,032
    You refering to HTML form tags or SQL queries???
    Josh
    Get these: Mozilla Opera OpenBSD
    I have books for sale: "MCSD in a Nutshell" and "VB Distributed Exam Cram" - PM me for details. Will also trade for a decent ATX Pentium 2 MB/CPU/RAM combo.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Oct 2000
    Location
    Québec, Canada
    Posts
    212
    Ok, my fault; I wasn't explicit enough.

    It may sound dumb but just plain HTML, how can I add dynamically element to SELECT ?

    Thanks
    Regards,

    El-Nino

  4. #4
    Frenzied Member
    Join Date
    Feb 2001
    Posts
    1,140
    [2nd Attempt to Post]

    What, are Josh, Monte, and me the only ones working this forum?

    Nino, you can build an loop and write your options.

    Code:
      <select name='mySelect'>
        <%
          for i = 0 to UBound(MyOptions, 1)
            %>
              <option value='<%=MyOptions(0, i)%>'><%=MyOptions(1, i)%></option>
            <%
          next 'i
        %>
      </select>
    'Course, there are a dozen different ways I could've done that: not use an array, use Response.Write to cut down on the <% %>, yadda yadda
    Travis, Kung Foo Journeyman
    As always, RTFM.

    WWW Standards: HTML 4.01, CSS Level 2, ECMA 262 Bindings to DOM Level 1, JavaScript 1.3 Guide and Reference
    Perl: Learn Perl, Llama, Camel, Cookbook, Perl Monks, Perl Mongers, O'Reilly's Perl.com, ActiveState, CPAN, TPJ, and use Perl;
    YBMS, but Mozilla doesn't.

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Oct 2000
    Location
    Québec, Canada
    Posts
    212
    Thank you Ciberthug, but that's not what i was looking for;
    I figured out how to do that in asp, but if the users decides to add an element to existing options I enumerate in asp ?

    This is in a form to add a new record to our db.
    It's working well, but since there are no combobox in HTML, i choose to use textboxes in conjunction with listbox (synchronized). needless to say, my boss didn't like it as much as I did lol.

    So he asked me to redesign the form w/o textboxes and just buttons instead where the user should click and then an inputbox would ask them what they would like to add...

    I just need the part where in vb i would have done this :

    cboItems.additem "MyNewItem"
    cboItems.Text = "MyNewItem"

    Thanks !
    Regards,

    El-Nino

  6. #6
    Frenzied Member monte96's Avatar
    Join Date
    Sep 2000
    Location
    Somewhere in AZ
    Posts
    1,379
    Pretty much the same in VBScript except the [] are () and you don't need the ; at the end of the line.
    oOOo--oOOo
    __/\/\onte96
    oOOo--oOOo
    Senior Programmer/Analyst
    MCP
    [email protected]
    [email protected]


    Your results may vary.. some restrictions may apply.. pricing and participation may vary.. not available in all states.. professional driver closed course..quantities limited..

  7. #7
    Frenzied Member monte96's Avatar
    Join Date
    Sep 2000
    Location
    Somewhere in AZ
    Posts
    1,379
    I think for VBScript it is something like this:
    Code:
    <script language=VBScript>
    Sub addNew
    	Dim objOption
    	Set objOption = document.createElement("OPTION");
    	objOption.innerText = 'Whatever'
    	objOption.value = '5'
    	myForm.mySelect.options.add(objOption)
    	Set objOption = Nothing
    End Sub
    </script>
    oOOo--oOOo
    __/\/\onte96
    oOOo--oOOo
    Senior Programmer/Analyst
    MCP
    [email protected]
    [email protected]


    Your results may vary.. some restrictions may apply.. pricing and participation may vary.. not available in all states.. professional driver closed course..quantities limited..

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Oct 2000
    Location
    Québec, Canada
    Posts
    212


    Ok thanks for the reply, but have you tried your script ?
    It's not working.
    I can't mix Vbscript & javascript so I'll find another way I guess... !

    Thanks for the reply again !
    Regards,

    El-Nino

  9. #9
    Frenzied Member
    Join Date
    Feb 2001
    Posts
    1,140
    Who's script, mine or Monte's? I told you mine was off.

    But what do you mean you can't mix VBScript and JavaScript? They can't be in the same script tag, but... I didn't realize they couldn't be on the same page.

    I would check on that, but I don't ever use VBScirpt for client-side, so I don't care. I use VBScript for the ASP server-side and JavaScript for the client-side.
    Travis, Kung Foo Journeyman
    As always, RTFM.

    WWW Standards: HTML 4.01, CSS Level 2, ECMA 262 Bindings to DOM Level 1, JavaScript 1.3 Guide and Reference
    Perl: Learn Perl, Llama, Camel, Cookbook, Perl Monks, Perl Mongers, O'Reilly's Perl.com, ActiveState, CPAN, TPJ, and use Perl;
    YBMS, but Mozilla doesn't.

  10. #10

    Thread Starter
    Addicted Member
    Join Date
    Oct 2000
    Location
    Québec, Canada
    Posts
    212
    Monte's script.
    I'm sorry for the misunderstanding; when I said I couldn't mix VBScript and javascript, I meant that I thought Vbscript couldn't call a function in javascript... Am I wrong ?
    Anyway, I found a solution, I used another way w/o adding options !

    Thanks anyway guys !
    VBWorld is the best place on the web !
    Regards,

    El-Nino

  11. #11
    Frenzied Member
    Join Date
    Feb 2001
    Posts
    1,140
    Oh, no, you are right. VBScript couldn't call a JavaScript function and vice versa. They would pretty much run as two seperate programs with their own memory space ontop of the page. They could access the same page elements, though, but not each other.
    Travis, Kung Foo Journeyman
    As always, RTFM.

    WWW Standards: HTML 4.01, CSS Level 2, ECMA 262 Bindings to DOM Level 1, JavaScript 1.3 Guide and Reference
    Perl: Learn Perl, Llama, Camel, Cookbook, Perl Monks, Perl Mongers, O'Reilly's Perl.com, ActiveState, CPAN, TPJ, and use Perl;
    YBMS, but Mozilla doesn't.

  12. #12
    Frenzied Member monte96's Avatar
    Join Date
    Sep 2000
    Location
    Somewhere in AZ
    Posts
    1,379
    I was doing that from the top (or maybe the bottom?) of my head.. didn't bother to test it... should have gotten you close though....

    like:
    Code:
    <script language=VBScript>
    Sub addNew
    	Dim objOption
    	Set objOption = document.createElement("OPTION");
    	myForm.mySelect.options.add(objOption)
    	//Assuming your form is named myForm and your select
    	//is named mySelect
    	objOption.innerText = 'Whatever'
    	objOption.value = '5'
    	Set objOption = Nothing
    End Sub
    oOOo--oOOo
    __/\/\onte96
    oOOo--oOOo
    Senior Programmer/Analyst
    MCP
    [email protected]
    [email protected]


    Your results may vary.. some restrictions may apply.. pricing and participation may vary.. not available in all states.. professional driver closed course..quantities limited..

  13. #13

    Thread Starter
    Addicted Member
    Join Date
    Oct 2000
    Location
    Québec, Canada
    Posts
    212
    Hehe monte's I'm not that dumb, Yet ( )

    I modified your script but couldn't get it to work, plus you forgot the Sub() and left javascript's ";"

    Thanks anyway !
    Regards,

    El-Nino

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