B4J Question [ Jserver with b4x_ws.js ] 2 buttons with the same id, only 1 activates the server function

Waldemar Lima

Well-Known Member
Licensed User
hello everyone !

i am studying about b4x_ws.js and Jserver , i have 2 buttons with same ID, but only the " first button " call function on Websocket Handler...

html >

HTML:
<html lang="en"><head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, shrink-to-fit=no">
    <title>UltimateTruco_Inventory_Sounds</title>
    <link rel="stylesheet" href="/bootstrap/css/bootstrap.min.css">
    <link rel="stylesheet" href="/fonts/font-awesome.min.css">
    <link rel="stylesheet" href="/styles.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.js"></script>
<script src="/cdn/b4j_ws.js"></script>
<script src="/cdn/reconnecting-websocket.js"></script>
</head>

<body><button class="btn btn-primary" id="deletar" type="button">Button</button><button class="btn btn-primary" id="deletar" type="button">Button</button><div style="margin-left: 50px;">
    <script>
    $(document).ready(function() {
        b4j_connect("127.0.0.1:80/ws");           
    });
    </script>
</div>
    <script src="/assets/bootstrap/js/bootstrap.min.js"></script>
    <script id="bs-live-reload" data-sseport="59454" data-lastchange="1633923149807" src="/js/livereload.js"></script>


</body></html>

Jserver Websocket Handler :
B4X:
'WebSocket class
Sub Class_Globals
    Private ws As WebSocket
    Private deletar As JQueryElement
End Sub

Public Sub Initialize
  
End Sub

Private Sub WebSocket_Connected (WebSocket1 As WebSocket)
    ws = WebSocket1
  
    Log("new user connected")
  
End Sub

Private Sub WebSocket_Disconnected

End Sub

Sub deletar_Click (Params As Map)
    Log("deletar clicked> "&Params)
  
    ws.Eval("alert('works');",Null)
    ws.Flush
  
End Sub

shouldn't the 2 buttons with the same id activate the same event?
 

aeric

Expert
Licensed User
Longtime User
So how do I create a list of cards that have the same button called: Delete, and identify each one individually on the Server?
If you work with JavaScript/jQuery you can work with class name using selector.
 
Upvote 0
Top