Link to home
Start Free TrialLog in
Avatar of digitalZo
digitalZoFlag for India

asked on

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?
Avatar of MrAgile
MrAgile
Flag of Australia image

Hi There,

Please post the code.

Sean
Avatar of b0lsc0tt
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
Avatar of digitalZo

ASKER

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.
ASKER CERTIFIED SOLUTION
Avatar of Michel Plungjan
Michel Plungjan
Flag of Denmark image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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?
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
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?
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.
<<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.
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
then you need to read the cookie clientside in the return from the postback.
>>>>>>>>.

any idea on how to go about doing it?