Antwise community forums

Full Version: Parameter 'this'
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi,

I'd want to fire a button with this code, but from antview, outside the button. I fon't figure out how to sustitute 'this' in call.

     onmousedown="iniciarBusqueda('button1',this);"

id="viewns_Z7_AVEQAI930OBRD02JPMTPG21004_:form1:button1"
type="submit"
name="viewns_Z7_AVEQAI930OBRD02JPMTPG21004_:form1:button1"

Thanks in advance.
Regards.
(2023-09-28, 15:11:36)carlos@agpsoftware.com Wrote: [ -> ]Hi,

I'd want to fire a button with this code, but from antview, outside the button. I fon't figure out how to sustitute 'this' in call.

     onmousedown="iniciarBusqueda('button1',this);"

id="viewns_Z7_AVEQAI930OBRD02JPMTPG21004_:form1:button1"
type="submit"
name="viewns_Z7_AVEQAI930OBRD02JPMTPG21004_:form1:button1"

Thanks in advance.
Regards.

Hello,

What I do in these cases is to create a simple test html page.

Here's my example:
PHP Code:
<html>
  <script>
      function testing(a,b){
        window.alert("hello")
      }
  </script>
</
head>
<
body>
    <form id="login" class="login" action="thankYou.html">
        <div class="loginName">
            <label for="username">UserName</label>
            <input type="text" name="username" placeholder="User Name" required />
        </div>

        <div class="loginBtn">
            <button id="submit" type="submit" onmousedown="testing(1,this);" name="submit">Login</button>
        </div>
    </form>

</
body>
</
html

I saved the above as "test.html" then opened it in Microsoft Edge.
Clicking the button pops up the alert button.
So the basics work.

Next step... figure out what "this" evaluates to (I have a pretty good idea, but it is best to make sure).
The way to do that is to put a breakpoint on the line with the alert.

Press F12 while in Microsoft Edge. This will then open Developer Tools for the page "test.html".
Go to the tab page named "Sources".
Click on "test.html" and put a break point on line 4, see this screenshot:
[attachment=36]
Now click on the button in the test page and you'll find that the break point is hit.
You can see the values already, also by hovering with the mouse, but another method to inspect the values in the function are to type the variable names in the console area at the bottom of the screen.
[attachment=37]
As you can see above, the value "this" evaluates to the button object.

So if you want to call that function from somewhere else, instead of the onmouseclick, then you can pass the button object instead of "this" and it all should work the same.
One way to get the button object in a variable to pass is to use the document.getElementById javascript function.
You can figure out the code for that while still in the debug session...
eg. see:
  [attachment=38]

PS: Please note that you can invoke that same debugger directly from within AntView (also press F12), for more info on that see Debug Anonymous javascript functions

PS2: Screenshots are only visible when logged in.
--
Wil
Hi,

Many thanks for answering.
Great: I use developper, got object Id and I managed to have it working.

m.cscript = "iniciarBusqueda('button1', "
m.cscript = m.cscript + 'document.getElementById("viewns_Z7_AVEQAI930OBRD02JPMTPG21004_:form1:button1")'
m.cscript = m.cscript + ");"

thisform.oantView.executeScript(m.cscript)

I'm beggining to hope to convert my project to work with Antview, instead of old IE objects.
Thanks again.