Dropdown update from Iframe

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?
LVL 10
digitalZoAsked:
Who is Participating?
 
Michel PlungjanIT ExpertCommented:
parent.document.getElementById('ctl00_ContentPlaceHolder1_ddl_ri_vname').selectedIndex =
(parent.document.getElementById('ctl00_ContentPlaceHolder1_ddl_ri_vname').options.length-1)
0
 
MrAgileCommented:
Hi There,

Please post the code.

Sean
0
 
b0lsc0ttIT ManagerCommented:
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
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
digitalZoAuthor Commented:
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
 
digitalZoAuthor Commented:
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
 
Michel PlungjanIT ExpertCommented:
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
 
digitalZoAuthor Commented:
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
 
Michel PlungjanIT ExpertCommented:
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
 
digitalZoAuthor Commented:
<<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
 
Michel PlungjanIT ExpertCommented:
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
 
digitalZoAuthor Commented:
then you need to read the cookie clientside in the return from the postback.
>>>>>>>>.

any idea on how to go about doing it?
0
 
digitalZoAuthor Commented:
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.