PDA

View Full Version : Javascript form item references



CGibson
2015-07-02, 09:03
Hello,

I have little to no web development knowledge and I'm learning as I progress.

In my app, I have a canvas section that contains a combo box, textbox and command buttons.
Is it possible to reference the text in the textbox from a command button?

I know this can be done with a regular desktop app, although I am having difficulty in a web app.

Here is my javascript code:


function client_secSearch_cmdSearch_click()
{
// var searchText = Lianja.get("client.secSearch.txtSearch").text;
var tsearch = Lianja.get("client.secSearch.txtSearch");
var searchText = tsearch.text;
alert("Text is " + searchText);
};


Regardless of the text placed in the textbox, the searchText always seems to be blank.

Am I coding this correctly or should this be done another way?

Cory

barrymavin
2015-07-02, 09:20
Hi Cory,

A UI control that is in a javascript canvas section can be referenced using the "id" of the UI control.

So if you have a text field with the id mytextfield you can just reference myfield.text

yvonne.milne
2015-07-02, 09:22
Hi Cory,

See here for more details: http://www.lianja.com/resources/blog/39-coding-tips/412-the-lianja-html5-client#p8

Also, have a look at example_webapp3, the 'Lianja Canvas Section Web UI Demo'.

Regards,

Yvonne

CGibson
2015-07-02, 11:18
Hello,

Thank you both for your response.

After modifying my code to only reference the field ID, there was still an issue.
It turns out the issue what my naming convention.

I had to change 'txtSearch' to 'txtsearch'.
This now seems to work.

I have a second issue I would like to address.
Based on the above comments, I changed some other code for the combo box.

Is it possible to change the textbox input mask based on the selected combo box value?
This doesn't seem to work in the Web App View.


function client_secsearch_cbosearchwhat_interactivechange()
{
switch (upper(cbosearchwhat.text))
{
case "CLIENT NUMBER (XX####)":
txtsearch.inputmask = "^^9999";
break;
case "PHONE (##########)":
txtsearch.inputmask = "9999999999";
break;
case "ADDRESS":
case "CLIENT NAME":
txtsearch.inputmask = replicate("!",30);
break;
}
};


I'm not sure if this has any effect, although once the web app view is loaded, opening the debug window shows the following error:


TypeError: null is not an object (evaluating 'psection.cursor.refreshcurrent = true')


When the web app view is loaded, the input mask remains the same as the last reference used in the pages workspace.

Thanks,
Cory

yvonne.milne
2015-07-02, 12:07
Hi Cory,

Try using the 'Change' (changed()) delegate instead of 'Interactive Change'.

Regards,

Yvonne

CGibson
2015-07-02, 12:15
Hi Yvonne,

That change seems to make a difference.
Thank you for the suggestion.

Cory