B4J Question Click checkbox in webview and submit using javascript

mcqueccu

Well-Known Member
Licensed User
Longtime User
Let me start by saying I am a noob in javascript.

I was working with a webpage manipulating some items from B4J, and this https://www.b4x.com/android/forum/t...es-of-an-html-form-in-a-webview-object.47072/ thread helped me and I am now in the final stage.

The last page after login has multiple checkboxes with classes. The SUBMIT button is disabled until one checkbox is clicked, and the button becomes active.

HTML:
<label class="customcheck">Select
 <input type="checkbox" class="check" name="nominee" value="47">
  <span class="checkmark"></span>
  </label>


<label class="customcheck">Select
 <input type="checkbox" class="check" name="nominee" value="48">
  <span class="checkmark"></span>
</label>

There is this javascript on the page.
JavaScript:
<script type="text/javascript">
        $(document).ready(function(){
            $('.check').click(function() {
                $('.check').not(this).prop('checked', false);
            });
            
            var checkboxes = $("input[type='checkbox']"),
                submitButt = $("input[type='submit']");

            checkboxes.click(function() {
                submitButt.attr("disabled", !checkboxes.is(":checked"));
            });           
        });
        </script>


These are my tries failed attempts.

B4X:
Private joWV As JavaObject = wv
    
'    joWV.RunMethodJO("getEngine", Null).RunMethod("executeScript", Array As String("document.getElementsByName('nominee')[3].value = 'true'"))
    'joWV.RunMethodJO("getEngine", Null).RunMethod("executeScript", Array As String("document.getElementsByClassName('check')[0].disabled = false"))
'    joWV.RunMethodJO("getEngine", Null).RunMethod("executeScript", Array As String("document.getElementsByClassName('check')[0].checked = true"))   
    'joWV.RunMethodJO("getEngine", Null).RunMethod("executeScript", Array As String("document.getElementsByClassName('check')[0].click();"))
    
    joWV.RunMethodJO("getEngine", Null).RunMethod("executeScript", Array ("document.forms[0].check[0].checked=true;"))
 
Solution
test checkbox 2: Check and Value

Edit:
'check')[1].?????

B4X:
Private Sub Button1_Click
    RunJavaScript($"document.getElementsByClassName('check')[1].checked = true;"$)
End Sub

Private Sub Button2_Click
    RunJavaScript($"document.getElementsByClassName('check')[1].checked = false;"$)
End Sub

Private Sub Button3_Click
    Wait For (RunJavaScript($"document.getElementsByClassName('check')[1].value;"$)) Complete(Html As String)
    xui.MsgboxAsync(Html, "Get value Check 1")
End Sub

TILogistic

Expert
Licensed User
Longtime User
test B4X:

see demo:
 
Upvote 0

TILogistic

Expert
Licensed User
Longtime User
test:
checkbox test, see the first check, with the buttons you can check or uncheck

1657269345451.png
 

Attachments

  • TestHTML1.zip
    3.3 KB · Views: 280
Upvote 0

TILogistic

Expert
Licensed User
Longtime User
test checkbox 2: Check and Value

Edit:
'check')[1].?????

B4X:
Private Sub Button1_Click
    RunJavaScript($"document.getElementsByClassName('check')[1].checked = true;"$)
End Sub

Private Sub Button2_Click
    RunJavaScript($"document.getElementsByClassName('check')[1].checked = false;"$)
End Sub

Private Sub Button3_Click
    Wait For (RunJavaScript($"document.getElementsByClassName('check')[1].value;"$)) Complete(Html As String)
    xui.MsgboxAsync(Html, "Get value Check 1")
End Sub
 
Last edited:
Upvote 1
Solution

TILogistic

Expert
Licensed User
Longtime User
Value and Checked
B4X:
Private Sub Button3_Click
    Wait For (RunJavaScript($"document.getElementsByClassName('check')[1].value;"$)) Complete(Value As String)
    Log(Value)
    Wait For (RunJavaScript($"document.getElementsByClassName('check')[1].checked;"$)) Complete(Checked As Boolean)
    Log(Checked)
End Sub
1657270801350.png
 
Upvote 0
Top