Click here to Skip to main content
Licence 
First Posted 8 Nov 2002
Views 149,365
Bookmarked 29 times

Creating a Dynamic Combo Box w/o Refreshing Page

By | 30 Jul 2003 | Article
..using IFRAME.

Introduction

Forms involving a dynamically-linked combo box have to waste a server-trip to fetch the values from the database to populate that combo box based on the value of a dependent combo box. Links to a number of approaches to handle dynamically-linked lists are listed in Charles Carol's excellent online book here. I discovered a cross-browser (well almost cross-browser ;-). I tested the code in IE 5, Netscape 6 & 7 and Mozilla 1.0 & it worked fine. IFRAME is not supported in NN 4.x and lower) method to populate a dynamically-linked List Box without refreshing the page, by using the IFRAME tag.

On selecting a country from the first combo box, the cities in that country, retrieved from the database are populated into the second combo. The second combo is actually present inside a frame-border-less IFRAME. A teeny-weeny JavaScript function allows the value of the combo box to be available to the outer form & be submitted.

The source code

The zipped source code file consists of 2 ASP files - where.asp & cities.asp & a MDB file City.mdb containing a table of countries & cities.

where.asp is the page that you have to load first, using IIS. It has a reference to the cities.asp page through the IFRAME.

Here's the teeny-weeny function in where.asp that enables the combo box present in the form in the IFRAME to be accessed by the parent form:

function getIframe()
{
//to access the element in the Form 
//contained in the page called by the IFrame, use
//parent.iframeName.document.iframeFormName.field.value
//here the IFrame element is assigned to the 
//hidden variable city in the parent Form

document.form1.city.value=parent.Iframe1.document.form2.elements[0].value;

}

The city element referred in the script above is a hidden tag.

When a country name is chosen from the combo box, the selected value is passed as a querystring to cities.asp.

<select 
   onchange='document.getElementById("Iframe1").src="cities.asp?country="+
   this.value'>

It refers to the following IFRAME defined in the same page.

<IFRAME id="Iframe1" name='Iframe1' 
  FRAMEBORDER=0 SCROLLING='no' WIDTH=120 HEIGHT=40></IFRAME>

Check this Microsoft link for an insight into the IFRAME tag. If you're impressed with what can be done with IFRAME, take a look at Searchlite v2. Also take a look at two other related articles:

Links

Feedback

Let me know if this article is a killer or a dud. Or whatever you felt.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

'Anil' Radhakrishna

Web Developer

India India

Member

'Anil' Radhakrishna is a seasoned developer who enjoys working with Microsoft tools & technologies. He blogs quite regularly about his his little discoveries and on Web development tips, tricks and trivia. You can find some of his unusual code samples & snippets at his Code Gallery.
 
Twitter - mvark

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
Questioniframe Pinmemberjguemez6:15 22 Apr '11  
GeneralCreating a Dynamic Combo Box w/o Refreshing Page PinmemberRayRit13:13 18 Nov '09  
QuestionCan you help me out by doing the same With PHP Pinmemberarunudu1:07 14 Dec '07  
Questioncan you upgrade this in asp.net Pinmemberpabidi1:33 27 Jun '07  
GeneralExpansion to 3 combo box Pinmembergeervanibs20:16 4 Jun '07  
GeneralThanks 4 this PinmemberCristiano Shrestha19:06 22 May '07  
QuestionHow to expand the select box to be 3 or more select box??? Pinmemberneo_msi2022:05 2 May '07  
GeneralThanks so much! [modified] Pinmemberenfleshjsc5:05 29 Mar '07  
QuestionHow do i extend it to three combo boxes Pinmemberbibha6:15 8 Aug '03  
AnswerRe: How do i extend it to three combo boxes Pinmembergeervanibs20:25 4 Jun '07  
You say u have created two frames on the parent page. Create only one frame in the parent page. and create the 2nd frame in the child form. It will work. totally u will three form. one the main page where u have the first frame. then the second form where u have the 2nd frame. and 3rd where u would have passed the value from the 2 form.
GeneralYou have a creative solution but... Pinmemberkbuchan2:19 4 Aug '03  
GeneralRe: You have a creative solution but... PinmemberRichard Deeming22:56 4 Aug '03  
GeneralJSP PinsussJuan Carlos Montenegro5:45 18 Dec '02  
Generalsometinh different Pinmembertommy skaue0:18 12 Nov '02  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web04 | 2.5.120529.1 | Last Updated 31 Jul 2003
Article Copyright 2002 by 'Anil' Radhakrishna
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid