INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • 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.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Help with ActiveXObject Microsoft.XMLHTTP

Help with ActiveXObject Microsoft.XMLHTTP

(OP)
Hello Everyone Smarter Than Me!

Before I get to the question first a little History on what I am working with. I am a Software Engineer currently working under a contract in a highly customized environment. The IDE that I am using (Not by my choice as I am a Java developer by Trade) uses a "JavaScript Runtime Environment" to treat JavaScript as a complied language. Needless to say this is a little odd and it was created because my employer had trouble finding enough developers that know other languages (This also seems odd) but there always seemed to be a ton of JavaScript people around.

Anyway now to the question. The code I am writing is product testing automation code that is going to save testing dollars eventually. Initially the testing was done by a team of testers whom would log into a website, run some tests by interacting with the website, and then get the results from the tests via the product that they are testing.

My code will do all the interaction with the device and the website and then compile all the results in an Ms. Excell spreadsheet for viewing. The problem is that my employer doesn't own the website that the testing is done from and there has been some changes lately that I am trying to overcome.

The problem is as follows.  

I have been using a Microsoft.XMLHTTP ActiveX Object to login to the website and do all the test manipulation and form submitting. The recent changes to the website have broken the automation code. The original form that I was working with contained a submit button as follows

<input id="submitReq" type="submit" value="task device"/>

and the id allowed the ActiveX control to find the button and submit the form.

Now the page has changed as follows.

There is no longer a submit button instead there is a standard button calling a javascript onclick which is then used to submit the form. The button and the javascript are below and as you can see the button has no id which makes finding and submitting the button very difficult.

CODE


<input type="button" class="button" value="Task Devices" onclick="submitRequestForm()"/>


        <script type="text/javascript">
            <![CDATA[
            function submitRequestForm()
            {
                var validations = new Object();
                var fieldNames = ["devices", "profile", "priority"];
                for (var key in fieldNames) {
                    try
                    {
                        document.getElementById("errorMessageSpace_" + fieldNames[key]).innerHTML = "";
                    }
                    catch(ex)
                    {
                    }
                }
                validations["devices"] = [
                {type: "required", errorAction: displayTaskingParamError, errorMsg: "Devices field cannot be empty!"},
                {type: "mask", regExp: /^(([!]?[\+]?([*?0-9A-Fa-f]{0,30}))|(([!]?[\+]?[0-9A-Fa-f]{0,30})?\/([0-9A-Fa-f]{0,30})?\/([*?0-9A-Fa-f]{0,30})?))(\s(([!]?[\+]?([*?0-9A-Fa-f]{0,30}))|(([!]?[\+]?[0-9A-Fa-f]{0,30})?\/([0-9A-Fa-f]{0,30})?\/([0-9A-Fa-f]{0,30})?)))*$/, errorAction: displayTaskingParamError, errorMsg: "Invalid devices list specification!"}];
                validations["profile"] = [
                {type: "required", errorAction: displayTaskingParamError, errorMsg: "Profile field cannot be empty!"},
                {type: "mask", regExp: /^[0-9]*$/, errorAction: displayTaskingParamError, errorMsg: "Invalid profile specification!"}];
                validations["priority"] = [
                {type: "required", errorAction: displayTaskingParamError, errorMsg: "Priority field cannot be empty!"},
                {type: "mask", regExp: /^[+-]?[0-9]*$/, errorAction: displayTaskingParamError, errorMsg: "Invalid priority specification!"},
                {type: "numberBetween", low: 0, high: 1000, errorAction: displayTaskingParamError, errorMsg: "Priority value must be between 0 and 1000!"}];
                var taskingRequestForm = document.getElementById('taskingForm');
                taskingRequestForm.elements["devices"].value = normalizeDevicesList(taskingRequestForm.devices.value);
                if (new FormValidator(taskingRequestForm, validations).validate(false))
                {
                    taskingRequestForm.submit();
                }
            }
            
            function displayTaskingParamError(field, validation)
            {
                try
                {
                    document.getElementById("errorMessageSpace_" + (field.name || field.id)).innerHTML = "*" + validation["errorMsg"];
                }
                catch(ex)
                {
                    alert(validation["errorMsg"]);
                }
            }
            ]]>
        </script>  

Can anyone tell me how to submit this page after the form is filled out using the Microsoft.XMLHTTP ActiveX Object? Is there a way?

Thanks in advance for any help that any of you can be.

Regards,

RE: Help with ActiveXObject Microsoft.XMLHTTP

[0]
>but there always seemed to be a ton of JavaScript people around.
That's true.
>as I am a Java developer by Trade
Good, we have java forums that need talent like you to help others...
    http://www.tek-tips.com/threadminder.cfm?pid=269
>Hello Everyone Smarter Than Me!
... so that you can show your talent there and prove that your are Smarter Than Most Others in your trade.

[1] This question has everything to do with javascript and has near to zero to do with activex. You should post the question to javascript forum in the followup related to the project.
    http://www.tek-tips.com/threadminder.cfm?pid=216

[2] I can give you the answer for this. You can get to the "standard button" element and continue the task as if it is being clicked like this.

    var taskingRequestForm = document.getElementById('taskingForm');
    var cinput=taskingRequestForm.getElementsByTagName("input");
    for (var i=0; i<cinput.length;i++) {
        if (cinput[i].value=="Task Devices") {
            cinput[i].onclick();
            break;
        }
    }

RE: Help with ActiveXObject Microsoft.XMLHTTP

[2.1] In case there might be elements with value "Task Device" as well (which eventually would happen one day as Murphy's Law trying to say) then you can guard against by checking the type as well (and if the more the better, className as well).

    var taskingRequestForm = document.getElementById('taskingForm');
    var cinput=taskingRequestForm.getElementsByTagName("input");
    for (var i=0; i<cinput.length;i++) {
        if (cinput[i].type.toLowerCase()=="button" && cinput[i].value=="Task Devices") {
            cinput[i].onclick();
            break;
        }
    }

ps: The use of toLowerCase() is just another added safety measure. Common ie/moz return "button" in lower case as a norm. (Your target user agent sure would be ie as you test activex.)

RE: Help with ActiveXObject Microsoft.XMLHTTP

(OP)
Tsuji,

I appreciate your response as this will help me greatly in getting my code working properly again!

Thank you,

Zero

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

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

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

Resources

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