By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,241 Members | 775 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,241 IT Pros & Developers. It's quick & easy.

changing contents of document.form.elements

P: n/a
The below function attempts to remove the contents of one form and
replace with the contents of another. Is this not possible? Why not?
It will make a big difference in the final solution to a problem I am
trying to solve.

Thanks for any advice!

wana
function change_form()
{
var f1 = window.opener.document.forms[0];
var f2 = window.opener.document.forms[1];
for (var i=0;i<f1.elements.length;i++)
{
delete f1.elements[i];
}
for (var i=0;i<f2.elements.length;i++)
{
f1.elements.push(f2.elements[i]);
}
}

Jul 23 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Lee
io*****@yahoo.com said:

The below function attempts to remove the contents of one form and
replace with the contents of another. Is this not possible? Why not?
It will make a big difference in the final solution to a problem I am
trying to solve.


My most important advice is to read some documentation, rather
than just guessing about what might work. This newsgroup's
FAQ is a good place to start:
http://www.jibbering.com/faq/

What is the problem you're trying to solve? Are the formss in
the same web site?

Jul 23 '05 #2

P: n/a
I know that you can access (as in view) the elements of a form like an
array but if you want to change the elements you have to use the DOM
(deleteChild, appendChild). But what I think is the best approach to
something like this is to change the styles so you hide/show different
forms. So your function would be:

function change_form()
{
var f1 = window.opener.document.forms[0*];
var f2 = window.opener.document.forms[1*];
f1.style.display = 'none';
f2.style.display = '';
}

If that doesn't work for you let me know and I can give you a DOM
example.

Jul 23 '05 #3

P: n/a


Lee wrote:
io*****@yahoo.com said:

The below function attempts to remove the contents of one form and
replace with the contents of another. Is this not possible? Why not?
It will make a big difference in the final solution to a problem I am
trying to solve.


My most important advice is to read some documentation, rather
than just guessing about what might work. This newsgroup's
FAQ is a good place to start:
http://www.jibbering.com/faq/

What is the problem you're trying to solve? Are the formss in
the same web site?


Thank you for the reference. I based my efforts on my understanding of
what should work with an array and applied it to objects, which act as
associative arrays. I am more familiar with Perl and PHP. The
different ways of doing the same thing can be confusing. In PHP, for
example, all arrays are associative. My reading on Javascript in my
O'Reilly book seemed to hint (without saying explicitly) that the same
is true in JS.

wana

Jul 23 '05 #4

P: n/a


LV_Indy wrote:
I know that you can access (as in view) the elements of a form like an
array but if you want to change the elements you have to use the DOM
(deleteChild, appendChild). But what I think is the best approach to
something like this is to change the styles so you hide/show different
forms. So your function would be:

function change_form()
{
var f1 = window.opener.document.forms[0*];
var f2 = window.opener.document.forms[1*];
f1.style.display = 'none';
f2.style.display = '';
}

If that doesn't work for you let me know and I can give you a DOM
example.


Excellent leads to a solution. Thank you so much!

wana

Jul 23 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.