digitalZo
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?
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
<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
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.IsStartupScriptRegis tered("Tes t")) Then
Dim temp As String
temp = "<script language='Javascript'>"
temp += " alert(""Successful;"");"
temp += " var newElm = document.createElement('op tion');"
temp += " newElm.text ='" + txtcompany.Text
temp += "'; newElm.value ='" + txtcompany.Text
temp += "'; parent.document.getElement ById('ctl0 0_ContentP laceHolder 1_ddl_ri_v name').opt ions.add(n ewElm);"
temp += " parent.document.getElement ById('mydi v').style. display='n one';"
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.
This is the code used you to add the value to the dropdown from the form in the Iframe:
If Not (Page.IsStartupScriptRegis
Dim temp As String
temp = "<script language='Javascript'>"
temp += " alert(""Successful;"");"
temp += " var newElm = document.createElement('op
temp += " newElm.text ='" + txtcompany.Text
temp += "'; newElm.value ='" + txtcompany.Text
temp += "'; parent.document.getElement
temp += " parent.document.getElement
temp += "</script>"
Page.RegisterStartupScript
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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?
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
Perhaps you need to send the new options to that postback too to include it in new forms from the server
ASKER
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?
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.
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.
ASKER
<<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.
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
It seems to me you are making your life quite complicated
ASKER
then you need to read the cookie clientside in the return from the postback.
>>>>>>>>.
any idea on how to go about doing it?
>>>>>>>>.
any idea on how to go about doing it?
ASKER
this is what i basically wanted to do:
https://www.experts-exchange.com/questions/23475072/Iframe-parent-page-refresh-data-update.html
https://www.experts-exchange.com/questions/23475072/Iframe-parent-page-refresh-data-update.html
Please post the code.
Sean