B4J Question [Server] Get id <li> [solved]

dar2o3

Active Member
Licensed User
Longtime User
Hi to all.

I have this

B4X:
<ul id="dropdown1" class="dropdown-content">
  <li id='1'><a href="#!">one</a></li>
  <li id='2'><a href="#!">two</a></li>
  <li class="divider"></li>
  <li id='3'><a href="#!">three</a></li>
</ul>

in my code this

B4X:
Sub dropdown1_Click (Params As Map)


End Sub

as I get the value of the label <a> <li> selected?

Get the id of the <li> selected is sufficient.
 
Last edited:

dar2o3

Active Member
Licensed User
Longtime User
There are actually several <ul> <li> nested

B4X:
<ul class="right hide-on-med-and-down" id="menuxa">

<ul id=Empresa class=dropdown-content>
    <li>
    <a href=../asegurado/empresas.html>Datos empresa</a>
    </li>
</ul>
<ul id=Viajes class=dropdown-content>
    <li><a href=../asegurado/viajes.html>Nuevo viaje</a>
    </li>
</ul>

<li>
    <a class=dropdown-button href=#! data-activates=Empresa>
      Empresa <i class=right><i class=material-icons>
   arrow_drop_down</i></i></a>

</li>

<li>
    <a class=dropdown-button href=#! data-activates=Viajes> Viajes<i class=right>
    <i class=material-icons> arrow_drop_down</i></i></a>

</li>

<li id=cierre name=cierre>
    <a href=#>Cerrar sesión</a>
</li>



</ul>

And

B4X:
Sub menuxa_Click (Params As Map)
    Dim target As String = Params.Get("target")
    Log(target)

End Sub

target is empty.

I am interested recover when the id = "cierre" is pressed


html text not has quotes because I copied the log, but it is correct, there is not the problem
 
Last edited:
Upvote 0

dar2o3

Active Member
Licensed User
Longtime User
Thanks for answering.

The result of the print the log is this.

B4X:
(MyMap) {which=1, metaKey=false, pageY=30, pageX=994, target=}

I am using the framework materializecss, not if the problem may come from the framework or am I doing something wrong.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Add this code to the Connected event (it adds a click event to the list items):
B4X:
ws.Eval($"
   $('#dropdown1 li').on('click', function () {
       b4j_raiseEvent("item_click", {index: $(this).index()});
     });"$, Null)
Handle the event with:
B4X:
Sub Item_Click (Params As Map)
   Log($"Clicked on item ${Params.Get("index")}"$)
End Sub
 
Upvote 0

dar2o3

Active Member
Licensed User
Longtime User
just perfect, now I can use this to get the text, interests me more than the index.

B4X:
ws.Eval($" $('#menuxa').on('click','li', function (){b4j_raiseEvent("item_click",{texto: $(this).text()});});"$, Null)

and

B4X:
Sub Item_Click (Params As Map)
   Log($"Clicked on item ${Params.Get("texto")}"$)
End Sub

Thank you very much for to answer my question.
 
Last edited:
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…