4

I have some input values contained within a bunch of divs and a form. I have a limited knowledge of js and would like to use greasemonkey to set the values when the page loads.

The following shows the order of divs and forms to get to the value.

<div data-role="page" id="finalTest">                    
  <div data-role="content">
    <form class="cmxform" id="ftForm">
      <div id="finalTestForOtherDiv" >
        <div data-role="fieldcontain" class="special-spacing">
                <div class="input-div">
                    <label id="finalTestBeforeAcTgrLabel" for="finalTestBeforeAcTg" data-insight="true" 
                        class="mandatory" data-default="mandatory"><img class="label-image" alt="" src="../Images/icon-alert.png" />AC V (T/G):</label>
                    <input type="text" id="finalTestBeforeAcTg" name="finalTestBeforeAcTg" value="" style="width:100px; display:inline-block;" 
                        data-bind="binder.BeforeAcTg"  data-bind-action-when-hidden="Ignore" />
                    <span class="ui-content" style="padding-left:7px;">V</span>
                    <div class="error-message"><ul></ul></div>

                </div>

Here is the script I've tried using but does nothing.

// ==UserScript==
// @name    Final Test
// @description Final test results
// @include https://techaccess.ad.qintra.com/WorkJobs/WorkJobs.aspx#finalTest
// ==/UserScript==

document.getElementById("finalTestBeforeAcTg").value = "0.00";
Cameron Darlington
  • 355
  • 2
  • 7
  • 14

2 Answers2

7
document.getElementById("finalTestBeforeAcTg").value = "your value";
Pavel Strakhov
  • 39,123
  • 5
  • 88
  • 127
3

If your script attempt is not working, it is likely because one or more of the following:

  1. The @include is too restrictive.
  2. The node does not exist yet. Is AJAX active on the page?
  3. Prerequisite javascript events must be triggered for the page to acknowledge or accept the new value.

For issue 1, change the script to:

// ==UserScript==
// @name        Final Test
// @description Final test results
// @include     http://techaccess.ad.qintra.com/WorkJobs/*
// @include     https://techaccess.ad.qintra.com/WorkJobs/*
// ==/UserScript==

alert ("Script start.");

var finTestInput    = document.getElementById ("finalTestBeforeAcTg");
if (finTestInput) {
    finTestInput.value  = "0.00";
}
else {
    alert ("The target input does not exist yet!")
}

Note that if you use Firebug (you should), change the alert()s to unsafeWindow.console.log()s.


For issue 2, use the waitForKeyElements utility. See this answer, for example.


For issue 3, There is little we can do without access to the page to suss out the proper sequence of events.
Give us access to the page, or Use Firebug (and the Events panel) to figure it out, or maybe a snapshot of both the page's HTML, and the page's JS files, at Pastebin.com will be enough (maybe).

Community
  • 1
  • 1
Brock Adams
  • 90,639
  • 22
  • 233
  • 295