B4J Question Is there a way to set/get textbox/area, similar to jqueryelement?

B4JExplorer

Active Member
Licensed User
Longtime User
Hi,

In a WebSocket application with several JQueryElements, is there a way to get and set values in a textbox or textarea, similar to the SetVal() and GetVal() for JQueryElements?

In other words, I'd like to do it within the B4J application, without embedding or writing js code, into the html. (aside from the minimum js code for using B4J).
 

billzhan

Active Member
Licensed User
Longtime User
try SetVal/GetVal, SetText/GetText and Sethtml/GetHtml.

My test here,all of them work fine:
B4X:
'html
<textarea rows="3" cols="30" id="textareafortest">
    textarea for test
</textarea>


'b4j
    Dim s1 As Future=textareafortest.GetHtml
    Dim s2 As Future=textareafortest.GetVal
    Dim s3 As Future=textareafortest.GetText  
    Log("GetHtml  "&s1.Value)
    Log("GetVal   "&s2.Value)  
    Log("Gettext   "&s3.Value)
  
    textareafortest.SetVal("jq set text")

According to http://api.jquery.com/text/ , choose you need.
The .text() method cannot be used on form inputs or scripts. To set or get the text value of input or textarea elements, use the .val() method. To get the value of a script element, use the .html() method.
 
Upvote 0

B4JExplorer

Active Member
Licensed User
Longtime User
That was the other missing piece, how to declare those blasted variables..

But textareafortest? How does B4J understand that this is a legitimate object, a textarea? I would just get a syntax error, trying to reference textareafortest.
 
Upvote 0

B4JExplorer

Active Member
Licensed User
Longtime User
That was the other missing piece, how to declare those blasted variables..

But textareafortest? How does B4J understand that this is a legitimate object, a textarea? I would just get a syntax error, trying to reference textareafortest.

textareafortest is a jqueryelement. Understood, thanks Erel and billzhan.
 
Upvote 0

B4JExplorer

Active Member
Licensed User
Longtime User
How do you insert a block of code, into a post? The More Options menu, just pops up a separate edit window. There's no icons or buttons for formatting code. I'm using Google Chrome.

I've done this in the forum before, but am drawing a blank now.



When the

Dim s1 As Future=ta_lastname.GetHtml

above is executed, there's a null pointer error.


*** Beginning of Code block ***

Sub ta_lastname_Click( Params As Map )

Main.AppLog("ta_lastname_Click :: Start")

Dim ta_lastname As JQueryElement

Dim s1 As Future=ta_lastname.GetHtml
Dim s2 As Future=ta_lastname.GetVal
Dim s3 As Future=ta_lastname.GetText

Log("GetHtml "&s1.Value)
Log("GetVal "&s2.Value)
Log("Gettext "&s3.Value)

ta_lastname.SetVal("jq set text")


Main.AppLog("wb_txtlastname_Click :: End")

End Sub

*** End of Code block ***


Error occurred on line: 330 (....).
java.lang.NullPointerException
at anywheresoftware.b4j.object.WebSocket.access$1(WebSocket.java:110)
at anywheresoftware.b4j.object.WebSocket$JQueryElement.RunMethodWithResult(WebSocket.java:207)
at anywheresoftware.b4j.object.WebSocket$JQueryElement.GetHtml(WebSocket.java:252)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:563)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:221)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:156)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:93)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:82)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:84)
at anywheresoftware.b4j.object.WebSocketModule$Adapter$1.run(WebSocketModule.java:126)
at anywheresoftware.b4a.keywords.SimpleMessageLoop.runMessageLoop(SimpleMessageLoop.java:30)
at anywheresoftware.b4a.StandardBA.startMessageLoop(StandardBA.java:26)
at anywheresoftware.b4a.ShellBA.startMessageLoop(ShellBA.java:103)
at anywheresoftware.b4a.keywords.Common.StartMessageLoop(Common.java:131)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:292)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:156)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:93)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:82)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:84)
at b4j.example.main.main(main.java:28)
 
Upvote 0

B4JExplorer

Active Member
Licensed User
Longtime User
Not necessary. The problem is that the ta_lastname was declared inside the click routine, wasn't assigned, and therefore WAS null. When it's declared private in the Class_Globals, it works fine. Careless mistake on my part.

Looks good, thanks.
 
Upvote 0

TomDuncan

Active Member
Licensed User
Longtime User
Hi,
I have inputs and text areas within a form.
Have tested the above code and the inputs work using this
B4X:
Sub SelectComment(id As String)
    Dim m As Map = DBUtils.ExecuteMap(Main.SQL1, "SELECT * FROM comment WHERE id = ?", Array As String(id))
    If m.IsInitialized = False Then
        iname.SetText("N/A")
    Else
        Log(m.Get("comment"))
        iname.SetVal(m.Get("name"))
        iemail.SetVal(m.Get("email"))
        icomment.SetVal("This is a test") 'm.Get("comment"))
        ireply.SetVal(m.Get("reply"))
    End If
End Sub

However the Textarea "icomment" does not work.
html code is here

B4X:
        <div class="w3-group">
        <textarea id="icomment" class="w3-input" Type="text"  style="width:100%">Comments here</textarea>
            <label class="w3-label">comment</label>
        </div>

Any thoughts anyone.
It did say something about .val() but not familiar with this.

Tom

Just did a test and commented out my tinyMCE code in the head.
And it works. So how can I get the code to work with the editor.
This is in the head

B4X:
        <script type="text/javascript">
            tinyMCE.init({
            mode : "textareas",
            theme : "simple"
            });
        </script>

I tested the GetHtml value and the code is correct.
But still no displayin the tinyMCE, even though the layout is correct.
 
Last edited:
Upvote 0

TomDuncan

Active Member
Licensed User
Longtime User
Here is a demo of what I am trying (yes very trying) to do.
The TinyMCE is the problem
use 127.0.0.1:8080/admin/index.html

Tom
 

Attachments

  • test_site.zip
    173.2 KB · Views: 312
Upvote 0
Top