Quick bit of Javascript help needed.
Discussion
I have a child window which I open in FancyBox to update the properties of a MySQL table row. On submit it automatically close and refreshes the table it was called from. It all works fine, but I now want to transfer the value of a radio button in the child form to the parent All I need to do is have the parent radio button take on the value of the checkbox on the child, ie: open or closed.
{{{
//============================================================+
//Used to close FancyBox and reload the calling page.
//============================================================+
function closeFB()
{
//window.opener.document.radioControls.statusRadio.value = document.updateForm.Status.value;
window.parent.location = window.parent.location.href;
parent.$.fancybox.close();
}
}}}
I can alter the syntax to window.parent.document etc... but that doesn't work either What am I missing?
{{{
//============================================================+
//Used to close FancyBox and reload the calling page.
//============================================================+
function closeFB()
{
//window.opener.document.radioControls.statusRadio.value = document.updateForm.Status.value;
window.parent.location = window.parent.location.href;
parent.$.fancybox.close();
}
}}}
I can alter the syntax to window.parent.document etc... but that doesn't work either What am I missing?
BliarOut said:
What a prat. I'm calling this on the on submit action of a form... And the radio's no longer have a value
So I've got the values of the radios' using their onclick property and I can pop them in an alert but I still can't set the value of the parent... How could I do that?
Errrm. How you are doing this - you have opened a new window, right? Did you do this with window.showModalDialog()? If so you can return a JavaScript array from the dialog box filled with as much data as you like. That, though, will be an IE only feature, sir. So I've got the values of the radios' using their onclick property and I can pop them in an alert but I still can't set the value of the parent... How could I do that?
So what's this "FancyBox" business? A js library? If so how is the dialog box implemented? If it's "all done with divs" you are actually already in the same page - shove your value in a hidden or something. This avoids "pop-up" blocker crap too.
I am constantly finding out new things about JavaScript at the moment. jQuery does seem to be the library of choice these days but, by God, it overcomplicates the most trivial little things - whilst making possible all sorts of other cool stuff.
Ahah. I found a recommendation.
On your "parent" window expose a javascript function that takes your data value and puts it somewhere. Then call that javascript function from the child window using
window.opener.myExposedJavaScriptFunction(param,param2);
Don't use "opener" myself but that might be worth a shot.
On your "parent" window expose a javascript function that takes your data value and puts it somewhere. Then call that javascript function from the child window using
window.opener.myExposedJavaScriptFunction(param,param2);
Don't use "opener" myself but that might be worth a shot.
I got it working with the code below but then hit another problem. The refresh of the parent then sets it back to it's default radio button and I can't be arsed to code my way out of it right now
FancyBox is a lightbox type library that I use in conjunction with another (niftycorners) to get a mac style window with rounded corners and transparency to display an inline iframe with transparency etc. It creates a very swish looking borderless window for data input/update in seconds.
If anyone is interested the working code is below, I changed the name of the Radio during testing...
{{{
//============================================================+
//Used to update the calling page.
//============================================================+
function updateParent()
{
callStatusVal = 0;
for( i = 0; i < document.updateForm.callStatus.length; i++ )
{
if( document.updateForm.callStatus[i].checked == true )
callStatusVal = document.updateForm.callStatus[i].value;
}
//alert( "Call Status Value Is = " + callStatusVal );
if (callStatusVal=='Open'){
window.parent.statusRadioOpen.checked = true;
}
if (callStatusVal=='Closed'){
window.parent.statusRadioClosed.checked = true;
}
window.parent.location = window.parent.location.href;
}
}}}
FancyBox is a lightbox type library that I use in conjunction with another (niftycorners) to get a mac style window with rounded corners and transparency to display an inline iframe with transparency etc. It creates a very swish looking borderless window for data input/update in seconds.
If anyone is interested the working code is below, I changed the name of the Radio during testing...
{{{
//============================================================+
//Used to update the calling page.
//============================================================+
function updateParent()
{
callStatusVal = 0;
for( i = 0; i < document.updateForm.callStatus.length; i++ )
{
if( document.updateForm.callStatus[i].checked == true )
callStatusVal = document.updateForm.callStatus[i].value;
}
//alert( "Call Status Value Is = " + callStatusVal );
if (callStatusVal=='Open'){
window.parent.statusRadioOpen.checked = true;
}
if (callStatusVal=='Closed'){
window.parent.statusRadioClosed.checked = true;
}
window.parent.location = window.parent.location.href;
}
}}}
Gassing Station | Computers, Gadgets & Stuff | Top of Page | What's New | My Stuff