2

Button click not triggering javascript function(InsertRecord()) in Chrome but working fine in IE.

<input id="submit" type="button" value="Request Access" onclick="InsertRecord()" style="width:160px;"/>


function InsertRecord()
    {
        var txtUserName = document.getElementById('txtUserName').value;
        var txtDept = document.getElementById('ddlDept').value;
        var txtClass = document.getElementById('txtClass').value;
        var txtRole = document.getElementById('ddlRole').value;
        var txtAccess = document.getElementById('ddlAccess').value;
        if (txtUserName.length != 0 || txtDept.length != 0 || txtClass.length !=0 || txtRole.length !=0 || txtAccess.length !=0)
        {
            var connection = new ActiveXObject("ADODB.Connection");
            var connectionstring = "Data Source=dvuksdcwsql001;Initial Catalog=RP_5500_AppDB;Persist Security Info=True;User ID=CPT_DEV;Password=Cpt%100@123;Provider=SQLOLEDB";
            connection.Open(connectionstring);
            var rs = new ActiveXObject("ADODB.Recordset");
            rs.Open("insert into Range_Plan_Access values('" + txtUserName + "','" + txtDept + "','" + txtClass + "','" + txtRole + "','" + txtAccess + "')", connection);
            alert("Access Requested Successfully!");            

            connection.close();
        }
        else
        {
            alert("Please enter a value for User Name \n Department \n Class \n Role \n Access Required!");
        }
    }  

Could you please let me know the issue here?

Thanks,

3
  • Hi Angelos, Can you please let me know how can I get it worked even in Chrome? Commented Aug 3, 2016 at 5:51
  • Check my updated answer, I think I have found a way to solve your problem without changing any of your existing code. Commented Aug 3, 2016 at 6:01
  • If you found any of the answers helpful, please remember to upvote them and accept the answer that helped you the most to solve your problem! Commented Aug 7, 2016 at 14:10

3 Answers 3

1

The issue lies with the ActiveXObject() calls as they are only supported in IE. Chrome uses a different plugin architecture called NPAPI. There is a cross-browser plugin framework, Firebreath, that might be of use to you.

UPDATE: After searching around a bit, I also found this discussion on the Google Chrome Help Forum, which states that IE Tab for Google Chrome might allow your existing code to run properly. Give it a shot!

Sign up to request clarification or add additional context in comments.

Comments

1

ActiveX is supported only in IE.

I think you have to avoid this use, because you are exposing your Database in client side, so anyone can manipulate your DB.

It is jut my opinion. Avoid to use ActiveX to do this work.

Create a webservice to do this work.

Hope it help you.

Comments

0

Chrome does not support ActiveX. You shouldn't be connecting to a database through the browser, you should have a serverside API that connects to the database. What you are trying to do is bad mkay!

4 Comments

Hi Adrain, Thank You. Its just a single page application for a Demo purpose and I do not want to create an API for now. Could you please let me know on the workaround?
There is no work around, Chrome does not support ActiveX. You are not going to get Chrome to create an ADO database connection. You can whip up an API very quickly.
@AdrianBrand actually there might be a workaround (as stated in my answer), although it is something that the end-user should install, instead of something the developer can do.
Why mess around with any of that? Creating an API is the right way to do it and it is incredibly easy.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.