Solved

Dropdown update from Iframe

Posted on 2008-06-23
12
231 Views
Last Modified: 2012-06-27
I have a dropdown and an Iframe in the main page. When the user enters the data in the iframe, the dropdown should update and automatically set it to the value entered by the user. Is there any way i can do this?
0
Comment
Question by:digitalZo
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
12 Comments
 
LVL 8

Expert Comment

by:MrAgile
ID: 21851079
Hi There,

Please post the code.

Sean
0
 
LVL 54

Expert Comment

by:b0lsc0tt
ID: 21852365
The data entered in the iframe is in a form and you submit the form, right?  The simple way is to add the target attribute to the form tag (the form in the iframe) and give it _parent as the value.  E.g.

<form target="_parent"

That will cause the form to submit to the page with the dropdown.  Make sure the page will process the form and then make the dropdown.  To have the dropdown show the submitted value as selected you need to have your script add selected="selected" to the option tag for that item.  You can use an If to check for that value as you go through the other options.

If you need specifics on how to do this we will need code.  Let me know if you have a question.

bol
0
 
LVL 10

Author Comment

by:digitalZo
ID: 21852666
Thanks b0lsc0tt for your reply. Now we are going somewhere.

This is the code used you to add the value to the dropdown from the form in the Iframe:

If Not (Page.IsStartupScriptRegistered("Test")) Then
          Dim temp As String
            temp = "<script language='Javascript'>"
            temp += " alert(""Successful;"");"
            temp += " var newElm = document.createElement('option');"
            temp += "  newElm.text ='" + txtcompany.Text
            temp += "';  newElm.value ='" + txtcompany.Text
            temp += "';  parent.document.getElementById('ctl00_ContentPlaceHolder1_ddl_ri_vname').options.add(newElm);"
            temp += " parent.document.getElementById('mydiv').style.display='none';"
            temp += "</script>"
            Page.RegisterStartupScript("Test", temp)
        End If

But how do i show the new data as selected?

Secondly, I'm using ASP.Net controls. the problem im facing is that while the data adds to the dropdown, it disappears on postback of another control. therefore, i have to refresh the whole page to keep it intact; but with this method i lose all the data in the form on the parent page.
0
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
LVL 75

Accepted Solution

by:
Michel Plungjan earned 500 total points
ID: 21855109
parent.document.getElementById('ctl00_ContentPlaceHolder1_ddl_ri_vname').selectedIndex =
(parent.document.getElementById('ctl00_ContentPlaceHolder1_ddl_ri_vname').options.length-1)
0
 
LVL 10

Author Comment

by:digitalZo
ID: 21862876
Thanks for that code. It worked. But the problem is the dropdown shows the selected data but when I click on another dropdown which autopostbacks, the selected new data disappears from the dropdown.

Is there any solution for this?
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 21862917
Impossible to tell without knowing what the autopostback does.
Perhaps you need to send the new options to that postback too to include it in new forms from the server
0
 
LVL 10

Author Comment

by:digitalZo
ID: 21862969
The autopostback fills the corresponding dropdown with related information. For example, dropdown "country" when selected will autopostback and fill the dropdown "state" in that selected country.

how do i send new options to the autopostback?
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 21863160
I do not understand (I do not do ASP so I apologise if it is obvious)
You have several controls - one you want to update with one code and the other is populated with other code

If the postback uses ajax I do not see why populating one select would influence the content of another.
If the postback refreshes the complete form, then you could save the new elements in a cookie and have the postback read that cookie - assuming the postback updated both selects.
0
 
LVL 10

Author Comment

by:digitalZo
ID: 21863221
<<If the postback uses ajax I do not see why populating one select would influence the content of another.>>

im not using ajax.
<<
If the postback refreshes the complete form, then you could save the new elements in a cookie and have the postback read that cookie - assuming the postback updated both selects.>>>

how do i do this? and wont it become too complicated because im using this one form [iframe] to be called in 10 different pages.
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 21863280
then you need to read the cookie clientside in the return from the postback.

It seems to me you are making your life quite complicated
0
 
LVL 10

Author Comment

by:digitalZo
ID: 21863320
then you need to read the cookie clientside in the return from the postback.
>>>>>>>>.

any idea on how to go about doing it?
0
 
LVL 10

Author Comment

by:digitalZo
ID: 21863321
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

626 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question