Welcome to the VanDyke Software Forums

Join the discussion today!


Go Back   VanDyke Software Forums > Scripting

Notices

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 04-05-2018, 05:02 PM
Chazuke Chazuke is offline
Registered User
 
Join Date: Apr 2018
Posts: 2
Custom IE Dialog with Javascript

Hi,

I'm trying to create my own custom dialog box using the CreateObject("InternetExplorer.Application") function. I am able to feed the IE object HTML just fine, but I tried to add a small Javascript portion to the HTML but it doesn't appear to be working. Is it possible to have Javascript run in an IE object spawned by SecureCRT?

If the answer to the above is no, then what would be the best way to go about toggling a series of checkboxes in HTML without the use of Javascript?
Reply With Quote
  #2  
Old 04-05-2018, 05:28 PM
ekoranyi ekoranyi is offline
VanDyke Technical Support
 
Join Date: Jan 2017
Posts: 654
Hi Chazuke,

We have a couple of example scripts that make use of the IE object and demonstrate use of checkboxes, Send Lines One-by-One with Skips and Substitution Variables, and Convert Clipboard LF, CR, Space, and Tab.

You will generally create a checkbox then use a "onclick", see lines 59-62 of the ConvertClipboard example.

Code:
"<input type=checkbox id=reveal_before name-reveal_before CHECKED " & _
            "onclick=document.all('ButtonHandler').value='reveal_before';>" & _
            "Reveal non-printing characters</input>"
You could then use a Case/If to specify actions, lines 295-301 of the same script.
Code:
Case "reveal_before"
    If objCheckBoxRevealBefore.Checked Then
        objTextAreaBefore.Value = _
            RevealNonPrintingCharacters(strOriginalText)
    Else
        objTextAreaBefore.Value = strOriginalText
    End If
In the case of the example script you will find that we added a line of code to help streamline getting a reference to the checkbox.

Code:
Set objCheckBoxRevealBefore = g_objIE.Document.All("reveal_before")
Does this help get you the behavior you're looking for?
__________________
Thanks,
--Eric

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730

Last edited by ekoranyi; 04-05-2018 at 05:33 PM.
Reply With Quote
  #3  
Old 04-12-2018, 03:42 PM
Chazuke Chazuke is offline
Registered User
 
Join Date: Apr 2018
Posts: 2
Hmm I dont think this is quite what I was looking for. Let me try to post what I have here. I have a series of checkboxes with the same class. I use the class to retrieve a reference to them all. By default, the check all button will check all of the boxes. But if all of the boxes are checked, then it will uncheck all of the boxes. This code works when I have it as a separate HTML file open in IE, but does not work when I feed it into the IE object in the script using g_objIE.Document.Body.innerHTML = htmlBody

Code:
<div id='column0' style='float: left; width: 100px; height: 200px;'>
	<u>Consumer</u><br>
	<input type='checkbox' class='consumer' name='RWXP377' checked>RWXP377<br>
	<input type='checkbox' class='consumer' name='RWLP836' checked>RWLP836<br>
	<input type='checkbox' class='consumer' name='RWLP838' checked>RWLP838<br>
	<input type='checkbox' class='consumer' name='NAXP377' checked>NAXP377<br>
	<input type='checkbox' class='consumer' name='NALP765' checked>NALP765<br>
	<input type='checkbox' class='consumer' name='NALP767' checked>NALP767<br>
	<button name='checkAllConsumer' Onclick=checkUncheck('consumer')>Check all</button>
</div>

<script>
function checkAll(tag) {
    var checkboxes = document.getElementsByClassName(tag);
    for (var i = 0; i < checkboxes.length; i++) {
		if (!checkboxes[i].checked) {
			checkboxes[i].checked = true;
		}
    }
}
 
function uncheckAll(tag) {
    var checkboxes = document.getElementsByClassName(tag);
    for (var i = 0; i < checkboxes.length; i++) {
		if (checkboxes[i].checked) {
			checkboxes[i].checked = false;
		}
    }
}
 
function checkUncheck(tag) {
	var checkboxes = document.getElementsByClassName(tag);
	var check = 0;
	for (var i = 0; i < checkboxes.length; i++) {
		if (checkboxes[i].checked) {
			check++;
		}
	}
	if (check == checkboxes.length) {
		uncheckAll(tag);
	}
	else {
		checkAll(tag);
	}
}
</script>

Last edited by jdev; 04-12-2018 at 06:18 PM. Reason: wrap code in [code][/code] blocks for easire viewing
Reply With Quote
  #4  
Old 04-12-2018, 05:03 PM
ekoranyi ekoranyi is offline
VanDyke Technical Support
 
Join Date: Jan 2017
Posts: 654
Hi Chazuke,

Web programming is a bit outside of our wheelhouse. That being said, I believe the example below will help demonstrate using a select all checkbox.

Perhaps others in the community have different/betters ways of accomplishing this.

Code:
Dim intRowCount 
intRowCount = 5

Sub Main()

    Set g_objIE = CreateObject("InternetExplorer.Application")
    g_objIE.Offline = True
    g_objIE.navigate "about:blank"

    ' This loop is required to allow the IE object to finish loading...
     Do
         crt.Sleep 100
     Loop While g_objIE.Busy

    g_objIE.Document.body.Style.FontFamily = "Sans-Serif"
    g_objIE.Document.bgcolor= "AliceBlue"

    ' Inject the HTML code above into the IE object
    g_objIE.Document.Body.innerHTML = GeneratePageContent()

    Do
        crt.Sleep 25
    Loop While g_objIE.Busy

    ' Prevent the MenuBar, StatusBar, AddressBar, and Toolbar from
    ' being displayed as part of the IE window
    g_objIE.MenuBar = False
    g_objIE.StatusBar = False
    g_objIE.AddressBar = False
    g_objIE.Toolbar = False

    ' Set the initial size of the IE window
    g_objIE.height = 350
    g_objIE.width = 350

    ' Set the title of the IE window
    g_objIE.document.Title = "Checkbox example"
    g_objIE.Visible = True

    ' This code attempts to bring the IE window to the foreground.
    Set objShell = CreateObject("WScript.Shell")
    objShell.AppActivate g_objIE.document.Title

    ' This loop is required to allow the IE window to fully display
    ' before moving on
     Do
         crt.Sleep 100
     Loop While g_objIE.Busy

    Do
        ' If the user closes the IE window by Alt+F4 or clicking on the 'X'
            ' button, we'll detect that here, and exit the script if necessary.
            On Error Resume Next
                Err.Clear
                strAction = g_objIE.Document.All("ButtonHandler").Value
                If Err.Number <> 0 Then
                    Exit Sub
                End If
            On Error Goto 0

        Select Case LCase(strAction)


            Case "close"
                g_objIE.Quit
                exit sub

            Case "selectall"
                bChecked = g_objIE.Document.All("SelectAll").Checked

                For i = 0 To intRowCount
                    g_objIE.Document.All("chkbox"&i).Checked = bChecked
                Next

                g_objIE.Document.All("ButtonHandler").Value = ""

        End Select

        crt.Sleep 50
    Loop

End Sub


Function GeneratePageContent()

    strTable = _
        "<table name=tbl id=""tbl"" border=""1"" cellspacing=""1"" cellpadding=""5"">" &_
        "<thead>" &_
        "<tr>" &_
        "<th bgcolor=""A9A9A9""><input type='checkbox' id=""SelectAll"" name=""SelectAll"" onclick=""document.all('ButtonHandler').value='selectall';"" /></th>" &_
        "<th bgcolor=""A9A9A9"">  Field 1  </th>" &_
        "<th bgcolor=""A9A9A9"">  Field 2  </th>" &_
        "<th bgcolor=""A9A9A9"">  Field 3  </th>" &_
        "<th bgcolor=""A9A9A9"">  Field 4  </th>" &_
        "</tr>" &_
        "</thead>" &_
        "<tbody>"

    For i = 0 To intRowCount
        strTable = strTable &_
            "<tr>" &_
            "<td>" &_
            "<input type=""checkbox"" id=""chkbox" & i & """ value=""testing"" onclick=""document.all('ButtonHandler').value='chkbox" & i & "'"" />" &_
            "</td>" &_
            "<td>field 1</td>" &_
            "<td>field 2</td>" &_
            "<td>field 3</td>" &_
            "<td>field 4</td>" &_
            "</tr>"
    Next

    strTable = strTable & _
        "</tbody>" & _
        "</table>" & _
        "<br>" & _
        "<div style='display:inline-block; white-space:nowrap'>" & _
        "<BUTTON style=""background-color:#abb2b9 "" id=close name=close onclick=document.all('ButtonHandler').value='close';>Close</BUTTON>" &_
        "</div>" & _
        "<input name='ButtonHandler' type='hidden' value='Nothing Clicked Yet'>"

    GeneratePageContent = strTable

End Function
Does this help get you the behavior you're looking for?
__________________
Thanks,
--Eric

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730

Last edited by ekoranyi; 04-12-2018 at 05:08 PM.
Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -6. The time now is 07:43 PM.