Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > Beginning VB 6
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Beginning VB 6 For coders who are new to Visual Basic, working in VB version 6 (not .NET).
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning VB 6 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old February 11th, 2005, 06:31 AM
Registered User
 
Join Date: Feb 2005
Location: bangalore, karnataka, India.
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to preethi.c
Default regarding combo boxes using html and javascript

I want to use a combo box which dynamically accepts values from the user and the value should be added into the selection list of the combo box options using html and javascript.

preethi
Reply With Quote
  #2 (permalink)  
Old February 11th, 2005, 11:23 AM
Friend of Wrox
 
Join Date: Nov 2004
Location: Port Orchard, WA, USA.
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

I tried many ways of doing this, and wound up having to manipulate the .outerHTML property of the drop-down. Changing the .innerHTML had no effect.
So let’s say you never add carriage returns between the last element and the ending </select>. That means you have 9 characters for the ending.
So you could store all of the outerHTML—minus the last 9 characters.
Add to that <option value="...">...</option> for each new entry, followed by + </select>.
Reply With Quote
  #3 (permalink)  
Old February 11th, 2005, 10:25 PM
Registered User
 
Join Date: Feb 2005
Location: bangalore, karnataka, India.
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to preethi.c
Default

i want to add the options in a combo box dynamically using HTML and Javascript please tell me how to extend the size of the array in the code in this case.

preethi
Reply With Quote
  #4 (permalink)  
Old February 14th, 2005, 10:43 AM
Friend of Wrox
 
Join Date: Nov 2004
Location: Port Orchard, WA, USA.
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

Well, its not an array.

Let’s say your combo is:
Code:
   <select name="sel" id="sel">
       <option value="01" selected>2001</option>
       <option value="02"         >2002</option>
       <option value="03"         >2003</option>
   </select>
   and you want to add ‘2004’ on the end.
Further, let’s presume there are no CRs in the html, as I said before. (If you have spaces, CRs, tabs, whatever, I’ll let you do your own character counting...)

So then:
Code:
  function Add_04()
  {
    var ctl = document.all["sel"];           // Set a reference to the control
    var  s  = ctl.outerHTML;                 // Get its contents
    s =  s.substr(0, s.length - 9);          // Get rid of the </select> on the end
    s += "<option value="04">2004</option>"; // Add your new list item(s)
    s += "</select>";                        // Reconstruct the end of the html
    ctl.outerHTML = s;                       // Put the string into the control.
  }

Now your html would be:
Code:
   <select name="sel" id="sel">
       <option value="01" selected>2001</option>
       <option value="02"         >2002</option>
       <option value="03"         >2003</option>
   <option value="04">2004</option></select>
   (Note that because of the fairly primitive string handling, the new text went in right where the ‘</select>’ had been, and now ‘</select>’ follows immediately after the last item in the list, with no formatting. The browser won’t care...)
Reply With Quote
  #5 (permalink)  
Old March 3rd, 2005, 03:29 AM
Registered User
 
Join Date: Mar 2005
Location: Bangalore, KA, India.
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Brian.

It works well for me.
But could this codw works in Mozilla browser?

Thanks in advance,
Nickel

Reply With Quote
  #6 (permalink)  
Old March 3rd, 2005, 05:36 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , United Kingdom.
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
Default

why not just use the DOM?
function Add04()
{
    var oOption = document.createElement("option");
    oOption.value = "04";
    oOption.innerHTML = "2004";

    var oSelect = document.getElementById("sel");
    oSelect.appendChild(oOption);
}
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
3 combo boxes ttkt Beginning PHP 0 July 2nd, 2005 02:20 PM
Using xsl to create HTML combo boxes rdavisiii XSLT 4 November 23rd, 2004 04:40 AM
Combo Boxes tjs206 VB Databases Basics 2 December 10th, 2003 04:20 PM
Combo Boxes tjs206 VS.NET 2002/2003 7 November 7th, 2003 03:45 PM
Combo Boxes Louisa Beginning VB 6 2 September 10th, 2003 09:26 AM



All times are GMT -4. The time now is 03:54 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.