INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

HANDLE


PASSWORD
Remember Me
Forgot Password?

Come Join Us!

  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • Turn Off Ad Banners
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

E-mail*
Handle

Password
Verify P'word
*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
Partner Button
(Download This Button Today!)

Member Feedback

"Because of this forum, I continue to WOW! my clients!"

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
Check Out Our Whitepaper Library. Click Here.
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>

Start A New Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Promoting, selling, recruiting and student posting
are not allowed in the forums.
Posting Policies

LINK TO THIS FORUM!
(Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum)
TITLE: Quest Software solutions Forum at Tek-Tips
URL: http://www.tek-tips.com/threadminder.cfm?pid=351
DESCRIPTION: Quest Software solutions technical support forum and mutual help system for computer professionals. Selling and recruiting forbidden.

 
Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close