setfocus()

new BookmarkLockedFalling
jerry
Junior Member
**

jerry Avatar

Posts: 86Male

Post by jerry on May 10, 2014 23:28:27 GMT -5

Guys,

I'm having all kinds of problems getting a textbox to have the main focus in my program. I've used the textbox method setfocus(), but it does not work. Tried the javascript I found in this forum, also not effective.

What I have is a number of buttons providing "about", "help", etc when clicked on. When run, my program throws up a banner surrounded with buttons, no wait at this point, then it get's to the code below.

If the user enters text and clicks on "ACCEPT" all is well. However if text is entered into the textbox and the user hits <return>, instead of the input being accepted and the program continuing, it's as if the user has clicked on the first button. In this code, it's as i the "Pricers" button was pressed. Not what I need done.

Clearly I need a way to setfocus() on the textbox, so that when the user hits <return> the text is taken from the textbox and program flow starts after the wait as it should.

I just haven't found a way. Any suggestions?


in the begining of the program, just a string o buttons:

html "<br>"
button #a0, " Pricers ", [supportedPricers]
button #a1, " Help ", [help]
button #a2, " About ", [about]
button #a3, " Logout ", [logout]


html "Enter Part Number"
textbox #gettext, ""
'#gettext setfocus()
html "<script type='text/javascript'>document.getElementById('#gettext').focus()</script>"
link #action, "ACCEPT", [gottext]
wait

[gottext]
partnumber$ = #gettext contents$()

--- rest of program ---
An old guy that cant wait to retire!
StefanPendl
Global Moderator
*****

StefanPendl Avatar

Run for BASIC ...
Posts: 945

[b]Stefan[/b] - [a href=http://stefanpendl.runbasichosting.com/]Homepage[/a][br][br][b]Please give credit if you use code I post, no need to ask for permission.[/b][br][br]Run BASIC 1.01, Fire-/Waterfox (IE11, Edge), Windows 10 Professional x64, Intel Core i7-4710MQ 2.5GHz, 16GB RAM
jerry
Junior Member
**

jerry Avatar

Posts: 86Male

Post by jerry on May 11, 2014 20:21:23 GMT -5

Setting focus on teh button, does jut that, the button has the focus. Does not help.

User enters text into the text box, presses <return> and it behaves just like a button press. In the code snip above, the program branches to [supportedPricers], not continuing with on after the textbox like it should.

An old guy that cant wait to retire!
jerry
Junior Member
**

jerry Avatar

Posts: 86Male

Post by jerry on May 12, 2014 11:46:05 GMT -5

Here is some sample code to look at. When run, you can click "one", "two" or enter some text and click "accept" and it will work. However, if you enter some text and then press return, the action you get is the pressing of button number one. Not what I would expect.

What I'm asking for help with is, how do you get the strike of the <return> to grab the text from the textbox and not generate a button strike?

I've tried two methods of setfocus() on both buttons and textbox and it always behaves the same way. Seems to me that the buttons should ignore keyboard strikes. Can't set the focus on the link after the textbox. Shouldn't the link respond to <return> unless clicked on. How do I set this up?

I cant believe I'm the only one seeing this. Carl?

button #one, "One", [oneClicked]
print " ";

button #two, "Two", [twoClicked]
print " ";

textbox #a, ""
' does not work
' #a setfocus()
' does not work
' html "<script type='text/javascript'> document.getElementById('#a').focus() </script>"
link #action, "Accept", [texted]
print " ";
'
' one wait to rule them all!
'
wait

[oneClicked]
print "One was clicked!"
wait

[twoClicked]
print "Two was clicked!"
wait

[texted]
text$ = #a contents$()
print text$
wait

An old guy that cant wait to retire!
StefanPendl
Global Moderator
*****

StefanPendl Avatar

Run for BASIC ...
Posts: 945

[b]Stefan[/b] - [a href=http://stefanpendl.runbasichosting.com/]Homepage[/a][br][br][b]Please give credit if you use code I post, no need to ask for permission.[/b][br][br]Run BASIC 1.01, Fire-/Waterfox (IE11, Edge), Windows 10 Professional x64, Intel Core i7-4710MQ 2.5GHz, 16GB RAM
jerry
Junior Member
**

jerry Avatar

Posts: 86Male

An old guy that cant wait to retire!