Search code examples
javascripthtmlperlcgiactivexobject

Reading file in PERL using ActiveX


I have been trying to read a file in PERL using ActiveX Control. I was successful in reading the file using ActiveX Controls in HTML. So I changed the HTML code to PERL cgi using "Print" Statement. After that I am not able to read the file the file using ActiveX, other JavaScript functions are working good.

print "<script src='/EnvelopeUtility/EnvelopeJS.js'></script>";

Above line of code is used to invoke the external JavaScript.

print "<td><input type='button' name='btn1' value='Process' onClick='getData(document.getElementById('sampleFile').value)'></td>";

Above line of code is an button in HTML, which onClick invokes the JavaScript method getdata()

var obj = new ActiveXObject('Scripting.FileSystemObject'); 

Above line of code is present in external JavaScript which creates an ActiveX Object to read the file.

    readFile = obj.OpenTextFile(path, 1, false);
                while(!readFile.AtEndOfStream) 
                {
        readFile = obj.OpenTextFile(path, 1, false);
.................

Above line of code is the one which reads the file line be line.

The above code is working fine in HTML but in CGI after using print statement am not able to read the file. Please do suggest what should be changed in order to read the file.


Solution

  • You have a simple HTML error.

    onClick='getData(document.getElementById('sampleFile').value)'
    

    Your attribute value is delimited by ' characters, but you try to use literal ' characters as raw data inside the attribute.

    Consequently the value of the attribute becomes getData(document.getElementById( which isn't valid JavaScript.

    This would have been picked up if you had used a validator.

    If you want to use a ' as data in an attribute value delimited by ' then you have to represent it as &#39;.