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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

setting object1 = object2 causes error 2

Status
Not open for further replies.

1DMF

Programmer
Jan 18, 2005
8,795
GB
Hi,

I'm trying to make an object (file input) on one form = a file input on another form.

However when I make object1 = object2 I get the following error..
Wrong number of arguments or invalid property assignment

what am I doing wrong?

Code:
frm = document.getElementById('comp_visit_form');
parent.file_frame.document.getElementById('file_report') = frm.report;

and the form objects are as follows..
Code:
<input type="file" name="file_report" id="file_report" size="50" />

<input type="file" name="report" id="report" size="50" />

They are both the same object types, whay can't I assign one to the other?

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"

Google Rank Extractor -> Perl beta with FusionCharts
 
I've banged my head for long enough on this one.

from what I can tell it just isn't possible, i've even tried cloning and appending the node, nothing works.

It just won't let you clone, copy, append or update the DOM in any, way, shape or form with the details of one input of type 'file' to another.



"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"

Google Rank Extractor -> Perl beta with FusionCharts
 
Are you trying to assign the value of one to be the value of the other?

Lee
 
I was able to append the file input just fine.

It removes it from its original place and sticks it in the new one.

Here's an example of what I did:

Code:
function Copy_File_Input(source,dest){
var src=document.getElementById(source);
var dest=document.getElementById(dest);
dest.appendChild(src);
}

Code:
<form name=form_one>
<input type="file" name="myfile_one" id="myfile_one">
</form>

<hr>

<form name=form_two id="form_two">

</form>
<br>
<a href="#" onClick="Copy_File_Input('myfile_one','form_two'); return false;">Copy</a>

"source" is the ID of the file_input, and "dest" is the Id of the destination form.

It will in fact move the element and take its set value with it.
This was all in the same page, though I suspect as long as the elements are properly referenced it should work from a child page to its parent as well.

Of note is that IE8 seemingly blanks out the value, however it is in fact still there, and the file can be successfully uploaded. Though it seems no file is selected.

What you can't do is set the value of a file_input programmatically as that would be a security risk, as you could just set any arbitrary file path to it and upload a file from a users machine without their knowledge.





----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
ahh, Thanks Phil.

As I visually saw it being blank, it seemed as though it wasn't copying.

I was even using clone and append node, etc..

It appeared on the page, but the value showed blank, I guess I should have tried a bit harder instead of giving up.

I re-wrote the code to have sub form in an iframe and used cross frame scripting to manage the upload and AJAX DOM updates.

As it's all working now, I don't think it's worth my time re-writing it again, just to have it work the way I hoped it would to start with.

To the user it looks like one form and it all works like it's all AJAXified!

There are always many ways to skin the provebial 'webapp' cat!

Have a star my friend!

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"

Google Rank Extractor -> Perl beta with FusionCharts
 
Hi

1DMF, you may find this useful ( or at least interesting ) regarding your cross-document node cloning.
MDC - Node.cloneNode said:
To clone a node for appending to a different document, use importNode instead.
( [tt]Node.cloneNode[/tt]; Follow the link in the quote for an example. )

Feherke.
 
Thanks feherke.

At least I can consider this method for next time.

Do you know why import vs clone should be used, there wasn't really any info on why to use import, it was just syntax/usage info.

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"

Google Rank Extractor -> Perl beta with FusionCharts
 
Hi

The only hint I found is from the DOM ( the MDC page has the link in the Specification section ) :
DOM level 2 said:
Additional information is copied as appropriate to the nodeType, attempting to mirror the behavior expected if a fragment of XML or HTML source was copied from one document to another, [red]recognizing that the two documents may have different DTDs[/red] in the XML case.
DOM Level 2 Core: Document.importNode

Feherke.
 
Gotcha!

Assuming clone copies it relative to the DTD the element was cloned from.


"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"

Google Rank Extractor -> Perl beta with FusionCharts
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top