Click to See Complete Forum and Search --> : select text in textbox
neil9999
09-02-2003, 04:12 AM
Hi,
As you'll see in my last thread (http://forums.webdeveloper.com/showthread.php?threadid=16494&goto=newpost) I've now got a maths game which puts the cursor in a textbox. The only problem is that now 'answer' is not displayed in the textbox (attatched is my origional script so you know when 'answer' should come up). Would it be possible if 'answer' automaticly gets selected? This way, users know they need to put their answer there but they don't need to click in the box to do so.
Thanks,
Neil
lillu
09-02-2003, 05:27 AM
Hi Neil,
I knew you wanted that text back, so here you are: :)
document.getElementById('answer').value='answer';
document.getElementById('answer').focus();
document.getElementById('answer').select();
} //final curly braces
place this at the very end of the your next1() function.
Add these two lines at the end of function next1()
document.getElementById('answer').value="";
document.getElementById('answer').focus();
and change this line:
<body onload="document.getElementById('answer').focus();" bgcolor="#FF0000">
Look at the tutorials at W3Schools (http://www.w3schools.com/default.asp). It will help you write better scripts
neil9999
09-02-2003, 01:39 PM
Hi,
I put this code at the end of the script at the top of this thread:
document.getElementById('answer').focus();
document.getElementById('answer').select();
'answer' was written in the box already.
Thanks,
Neil
neil9999
09-02-2003, 02:08 PM
Is it possible to make it so if you press 'Enter' on the keyboard, it 'clicks' the button enter/Next?
Thanks again,
Neil
Originally posted by neil9999
Is it possible to make it so if you press 'Enter' on the keyboard, it 'clicks' the button enter/Next?
Yes, put this in your FORM tag:
onsubmit="return false; next1();"
[J]ona
neil9999
09-03-2003, 02:49 AM
Hi,
Thanks Jona, but the script you gave me doesn't work when the cursor is in the 'answer' box. I have to click outside it before it works.
My code's attatched.
Thanks,
Neil
P.s. Fang, that website looks quite good. I'll have a look at it soon. Thanks
like this:
.
.
<form onsubmit="return false; next1();">
<table ....
.
.
</table>
</form>
.
.
Look at that website sooner! ;)
neil9999
09-03-2003, 03:18 AM
Thanks, did that, same problem. I need function next1() to be activated whenever you press enter on the keyboard, wherever the cursor is, wherever the mouse is.
I can't look at the website sooner, i've got first day of school this term tomorrow, so I need to get ready for that. Probably at the weekend i'll look...
Thanks,
Neil
Add this before function next1()
document.onkeypress=function whichKey(e) {
var code="";
if (window.event) { //it's IE
code=window.event.keyCode;
}
else {
code=e.which;
}
if(code=="13") {
next1();
}
}
neil9999
09-03-2003, 04:22 AM
When I do that, when you first load the page and press enter on the keyboard, it says 'Wrong' even though it hasn't asked you a question. I've attatched what i've got now.
Also, will a visitor using another browser apart from IE expierience any other errors?
Thanks for all your help,
Neil
luke0
09-03-2003, 05:02 AM
if you want help
msn messenger me
lukes_trains@hotmail.com
document.onkeypress=function whichKey(e) {
if(document.getElementById('answer').value!="") {
var code="";
if (window.event) { //it's IE
code=window.event.keyCode;
}
else {
code=e.which;
}
if(code=="13") {
next1();
}
}
}
Look at the website I gave you. You need to understand the basics of HTML.
Your script is not valid HTML so errors can occur.
GavinPearce
09-06-2003, 07:26 AM
the idea is that people are helped on teh forum luke, u dont get them to add you to messenger just so yuo can build uyp your contacts, I no for a fact that you couldnt have helped this person, you dont have the skills.