Page 1 of 1

I need to focus in a textbox from a embed code (group)

Posted: Tue Jun 02, 2015 4:34 pm
by rincon0204
Hi Friends!

I need your help in this point:
I made an app using the code provided on lessons¨runrev¨com/m/4069/l/22836-how-do-i-use-the-browser-control , 'drawing' a form made with HTML with some textboxes.
However, i need that when the app starts, it focuses in the first of these textboxes... (Obviously on the web, it works. But not in the app)
Which lines i need to put on the code of LiveCode, to achieve focusing in the textbox (on the group browser, which contains the HTML content)?

I would thank your help.
Greetings!

Re: I need to focus in a textbox from a embed code (group)

Posted: Tue Jun 02, 2015 5:27 pm
by zaxos
Hi rincon, a piece of advice would be to first consult the dictionary and then the forum, most of the times you easily first the answers there.

Code: Select all

focus on field 1
OR

Code: Select all

focus on field "fieldName"
Where fieldName is the name of your field.

Re: I need to focus in a textbox from a embed code (group)

Posted: Tue Jun 02, 2015 5:30 pm
by zaxos
forgot to mention you have to add this code at you openStack handler, so the result would be:

Code: Select all

on openStack
focus on field "myField"
end openStack
Put this code in your stack.

Re: I need to focus in a textbox from a embed code (group)

Posted: Tue Jun 02, 2015 5:36 pm
by Klaus
Hi zaxos,

the TS is not talking about Livecode fields, but a "field" inside of the HTML/webpage in a browser! 8)


Best

Klaus

Re: I need to focus in a textbox from a embed code (group)

Posted: Tue Jun 02, 2015 5:45 pm
by rincon0204
Exactly, as Klaus says...
The focus must be on the webpage (exactly on the textbox), the focus isn't in a text control from LiveCode.

It's not enough with putting on the HTML code:
window.document.form1.name.focus();
when in the app this line doesn't have the same effect as on the web.

Re: I need to focus in a textbox from a embed code (group)

Posted: Tue Jun 02, 2015 5:53 pm
by zaxos
How did i miss that :oops:
Thanks for pointing out Klaus, i'l delete the posts :roll:
nvm, cant delete them.

Re: I need to focus in a textbox from a embed code (group)

Posted: Tue Jun 02, 2015 6:10 pm
by zaxos
As for rincons problem, well i dont think livecode has a function to do that, but my guess is that you could use a simple js code to achive it:

Code: Select all

<script>
window.onload = function() {
  document.getElementById("myField").focus();
};
</script>
Where myField is your input's name.
My guess is that js wont work with revBrowserOpen as i had problems in the past, so use revBrowserOpenCef instead.
EDIT: Just tested it on windows and works as expected...