INTELLIGENT WORK FORUMS FOR COMPUTER PROFESSIONALS
Come Join Us!
Are you a Computer / IT professional? Join Tek-Tips now!
- Talk With Other Members
- Be Notified Of Responses
To Your Posts
- Keyword Search
- One-Click Access To Your
Favorite Forums
- Automated Signatures
On Your Posts
- Best Of All, It's Free!
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.
Partner With Us!
"Best Of Breed" Forums Add Stickiness To Your Site

(Download This Button Today!)
Member Feedback
"...If there has ever been a justification needed for access to the net during working hours, just referring to this site should suffice. Fantastic!..."
Geography
Where in the world do Tek-Tips members come from?
|
how to create a MsComDlg.CommonDialog object in javascript
|
|
|
csq (Programmer) |
7 Feb 01 21:33 |
Hi all expert, I have a question to ask: I want to put a button on htm file which can open a dialog I can select file from local drive, it is like a <input type="file"> but because <input type="file"> can't preset the value. but when I use var cdl = new ActiveXObject("MsComDlg.CommonDialog"); to create a commondialog object, it doesn't work. It shows Automation server can't create object error. attached is my code, my software environment is window2000/IE5.5/office2000 <html> <head></head> <script > function getfile( ){ var cdl = new ActiveXObject("MsComDlg.CommonDialog"); cdl.showopen; this.document.form1.txtFile.value = cdl.filename; } </script> <form name="form1"> <input type = "text" name = "txtFile" > <input type = "button" value = "Browse ..." onClick="getfile )" > </form> </html> Thanks. Megi
|
|
|
nachi (Programmer) |
23 Jan 02 18:30 |
Hi Megi
I am currently running into the same problem you are having, did you ever find a solution?
Thanks arlene |
|
|
ullrich (Visitor) |
18 Apr 02 12:47 |
Well, first this is JavaScript, right? so it should be var cdl=new ActiveXObject("MsComDlg.CommonDialog"); cdl.ShowSave(); alert(cdl.FileTitle); // This is CASE significant Still, it doesnt work for me with some stupid 'van't init' message. What works is including the Object in your doc and using that: theForm.CommonDialog1.ShowSave(); var fn=theForm.CommonDialog1.FileTitle; ..... <OBJECT ID="CommonDialog1" WIDTH=0 HEIGHT=0 CLASSID="CLSID:F9043C85-F6F2-101A-A3C9-08002B2F49FB" CODEBASE=" http://activex.microsoft.com/controls/vb5/comdlg32.cab" <PARAM NAME="CancelError" VALUE="1"> <PARAM NAME="DialogTitle" VALUE="Select Data File"> <PARAM NAME="Filter" VALUE="Dynasty Data Files (*.civ)|*.civ|All Files (*.*)|*.*"> </OBJECT> Hope this helps Ullrich |
|
|
ullrich (Visitor) |
18 Apr 02 13:18 |
Hello, me again...
This works:
var cdl=new ActiveXObject("MsComDlg.CommonDialog");
cdl.MaxFileSize=256; cdl.DialogTitle="Select Data File"; cdl.Filter="Dynasty Data Files (*.civ)|*.civ|All Files (*.*)|*.*"; cdl.ShowSave(); alert(cdl.FileTitle);
Looks like you MUST initialize MaxFileSize.
Best regards Ullrich
|
|
|
xMC (Visitor) |
15 May 02 11:12 |
I attempted to use the code listed above, but alas... the server still can't create the object. Is there a meta tag being used the reference the MSComDlg.CommonDialog object? |
|
|
Rambeaut (Visitor) |
19 Jul 02 8:40 |
It (the Hello, me again version) worked for me!! |
|
|
WendyG (Visitor) |
2 Aug 02 10:17 |
Thanks Ullrich I was having problems in my Vb and including it in the dialog works |
|
|
Botolph (Programmer) |
4 Jul 03 12:01 |
To get around the "Automation server can't create object" error (and to avoid using ActiveX at all) try this:
<div id="divHidden" style="visibility: hidden; width: 0px; height: 0px"> <input type=file id="fileInput"> </div>
<input type=button value="click here to get a file" onclick="getFile();">
<script language=javascript> function getFile() { //Use the <input type='file'...> object to get a filename without showing the object. document.all["fileInput"].click(); var fileName = document.all["fileInput"].value; alert(fileName); } </script>
|
|
|
 |
|