Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

window.opener refresh select

Status
Not open for further replies.

fuadhamidov

Programmer
Sep 22, 2003
98
TR
hi

i have found and developed following sample code.
i don't know wihy it does not work

Code:
function callOnload() {
    var i = window.opener.form.elements[<%=fieldIndex%>].options.length;
    alert( i );
    alert( window.opener.form.elements[<%=fieldIndex%>].options[i] );
//it gives error after that statement
    window.opener.form.elements[ <%= fieldIndex %> ].options[ i ] = new Option( '<%= object.getName() %>' );
    if ( window.opener.progressWindow ) {
        window.opener.progressWindow.close()
    }
    window.close();
}

thanks for any help
 
alert( window.opener.form.elements[<%=fieldIndex%>].options );

is one higher than the last option.

A SELECT with 5 options has a length of 5 and their indexes (indicies?) are (0,1,2,3,4) so option(5) will throw an error.

Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rick Cook (No, I'm not Rick)

zen.gif
 
Change your code to this and see if it helps (after you've read mwolf's suggestion):

Code:
function callOnload() {
    var theForm = opener.document.forms['form_name'];
    var theSel = theForm.elements[<%=fieldIndex%>];
    var theLen = theSel.options.length;

    alert( theLen );
    theSel.options[ theLen ] = new Option( '<%= object.getName() %>', '<%= object.getName() %>');
    if ( window.opener.progressWindow ) {
        window.opener.progressWindow.close()
    }
    window.close();
}

*cLFlaVA
----------------------------
[tt]Sigs cause cancer.[/tt]
 
thanks cLFlaVA

but it gives same error message
"Server throws exception"

and i resend statement that i get error

Code:
    window.opener.form.elements[ <%= fieldIndex %> ].options[ i ] = new Option( '<%= object.getName() %>' );

or

Code:
    theSel.options[ theLen ] = new Option( '<%= object.getName() %>', '<%= object.getName() %>');

it refreshes page, calls methods from parent page, focus, ... but when i run the statement above it gives error.
 
as far as i search, the reason why codes above is not run, IE does not support such a state (= create Option from child browser in such a way).

Moizilla and Nescape support.

discusses same subject

finally i have found following code and run successfully.

Code:
    var oOption = window.opener.document.createElement( "option" );
    oOption.text = "<%= object.getName() %>";
    oOption.value = "<%= returnedId %>";
    oOption.selected = true;
    window.opener.document.getElementById( "<%= fieldId %>" ).appendChild( oOption );

but i face an other situation: althougth it creates an Option and selects it, its text is seen empty (not value of <%= object.getName() %> ).

it is enought for me. but someone may need to show its text also.
 
How about this?
Code:
// ...
var txtNode = document.createTextNode("<%= object.getName() %>");
oOption.appendChild(txtNode);
// ...

--Chessbot

"In that blessed region of Four Dimensions, shall we linger on the threshold of the Fifth, and not enter therein? Ah, no! [...] Then, yielding to our intellectual onset, the gates of the Sixth Dimension shall fly open; after that a Seventh, and then an Eighth -- --" Flatland, A. Square (E. A. Abbott)
 
To overCome the child not being able to create an option in the parent, write the function in the parent and call it from the child - it will work fine.

Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rick Cook (No, I'm not Rick)

zen.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top