B4J Question EvalWithResult - multiple results

jhagerup

Member
Licensed User
Longtime User
I am trying to get the id's for all textarea in a table.

B4X:
Dim f As Future
f = ws.EvalWithResult("return $(arguments[0]).attr(""id"")", Array As Object("textarea"))
Log(f.Value)

returns the first id correct, but I can't figure out how to get all id's

B4X:
Dim f2 As Future
ws.Eval("$(arguments[0]).each(function(){alert( $(this).attr(""id""))})", Array As Object("textarea"))

shows alerts with the correct id's, but when i try with

B4X:
Dim f3 As Future
f3 = ws.EvalWithResult("return $(arguments[0]).each(function(){return $(this).attr(""id"")})", Array As Object("textarea"))

I get a "strange" map with unrecognizable data like:
{11={}, 12={}, 13={}, prevObject={0={location={search=, hostname=localhost, protocol=http:.....

Please help
 

rwblinn

Well-Known Member
Licensed User
Longtime User
Hi,

try following

JavaScript Function in Index.html Script section
B4X:
function getids(){
  var ids = [];
  var elements = document.getElementsByTagName("textarea");
  for(var i=0;i<elements.length;i++){
    ids.push(elements[i].id)
  };
  return ids;
};

B4J Code (uses Websockets)
Dim f As Future = ws.RunFunctionWithResult("getids", Null)
Dim l As List = f.value
For i = 0 To l.Size - 1
Log(l.Get(i))
Next

Example project attached. The getids function can be extended by using a parameter of the element to get id's from.
 

Attachments

  • WebAppGetIDs.zip
    5.7 KB · Views: 298
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…