Quick bit of Javascript help needed.

Quick bit of Javascript help needed.

Author
Discussion

BliarOut

Original Poster:

72,857 posts

239 months

Tuesday 5th October 2010
quotequote all
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 irked 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 frown What am I missing?

cottonfoo

6,016 posts

210 months

Tuesday 5th October 2010
quotequote all
BliarOut said:
What am I missing?
jQuery.

130R

6,810 posts

206 months

Tuesday 5th October 2010
quotequote all
Think you just want: opener.document.myform ...

BliarOut

Original Poster:

72,857 posts

239 months

Tuesday 5th October 2010
quotequote all
Let me get this working first smile I'm planning to start using Ajax etc to make things more dynamic once I've got all the functionality I need but for consistencies sake I'd just like to do this with a simple js call.

BliarOut

Original Poster:

72,857 posts

239 months

Tuesday 5th October 2010
quotequote all
opener.document didn't work frown If it helps, I'm opening it in an iframe...

cottonfoo

6,016 posts

210 months

Tuesday 5th October 2010
quotequote all
It's the jQuery selectors you'll want rather than the AJAX helpers. Might be easier if you give those elements you want to deal with ids and reference them directly.

BliarOut

Original Poster:

72,857 posts

239 months

Tuesday 5th October 2010
quotequote all
What a prat. I'm calling this on the on submit action of a form... And the radio's no longer have a value banghead

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?

Don

28,377 posts

284 months

Tuesday 5th October 2010
quotequote all
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 banghead

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 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.


Don

28,377 posts

284 months

Tuesday 5th October 2010
quotequote all
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.

BliarOut

Original Poster:

72,857 posts

239 months

Tuesday 5th October 2010
quotequote all
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 biggrin

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;
}
}}}