| View previous topic :: View next topic |
| Author |
Message |
hazrizal84
Joined: 10 Jun 2008 Posts: 15
|
Posted: Tue Jun 10, 2008 1:37 pm Post subject: Help me.....onblur () |
|
|
hi..i really need help from those who can solve my prob..here there are:
<html>
<head>
<script language=javascript>
function isNumberKey(evt)
{
var charCode = (evt.which) ? evt.which : event.keyCode
if (charCode > 31 && (charCode < 47 || charCode > 57))
return false;
return true;
}
</script>
</head>
<body>
<p>Please enter your answer or type ( / ) if you don't know the answer.<br>
Your answer may not contain both numbers and ( / ) sign.<br><br>
34 + 54 = <input type=text size="6" onkeypress="return isNumberKey(event)" onblur=""></p>
<p>123 + 76 = <input type=text size="6" name="T1" onkeypress="return isNumberKey(event)" onblur=""></p>
<input type=submit value="Check Answer!">
</body>
</html>
User will be able to key in their answer in numerical form or just type slash ( / ) for unknown answer..the prob is, how can i build up the function in onblur() statement so that, when tab button been pressed to move to the other textbox, it will determine whether user key in number, slash or the combination of number and slash. message box will be popped up if user key in both number and slash in the space provided. |
|
| Back to top |
|
 |
|
|
rangana 500+ Club

Joined: 27 Feb 2008 Posts: 563 Location: Cebu City Philippines
|
Posted: Wed Jun 11, 2008 1:05 am Post subject: Re: Help me.....onblur () |
|
|
First of all, language is a deprecated attribute for script tag. Use type instead.
What will be the message if there was a number and slash combination? Will it throw an error? |
|
| Back to top |
|
 |
hazrizal84
Joined: 10 Jun 2008 Posts: 15
|
Posted: Wed Jun 11, 2008 1:10 am Post subject: Re: Help me.....onblur () |
|
|
the message sort of, "Invalid answer entered. You may not answer both numbers and slash!!"...
help me plzz....i really need your help.... |
|
| Back to top |
|
 |
rangana 500+ Club

Joined: 27 Feb 2008 Posts: 563 Location: Cebu City Philippines
|
Posted: Wed Jun 11, 2008 1:39 am Post subject: Re: Help me.....onblur () |
|
|
I'm unaware of what you want to execute if "/" does'nt exist in the value. This might help:
| Code: |
<html>
<head>
<script type="text/javascript">
window.onload=function()
{
var inps=document.getElementsByTagName('input');
for(var i=0;i<inps.length-1;i++)
{
inps[i].onblur=function()
{
if(this.value.indexOf('/'))
{
//What you want to execute here
}
else
alert('You admit you don\'t know the answer!');
}
}
}
</script>
</head>
<body>
<p>Please enter your answer or type ( / ) if you don't know the answer.<br>
Your answer may not contain both numbers and ( / ) sign.<br><br>
34 + 54 = <input type=text size="6"></p>
<p>123 + 76 = <input type=text size="6" name="T1"></p>
<input type=submit value="Check Answer!">
</body>
|
|
|
| Back to top |
|
 |
hazrizal84
Joined: 10 Jun 2008 Posts: 15
|
Posted: Wed Jun 11, 2008 1:49 am Post subject: Re: Help me.....onblur () |
|
|
| wow....!! what a wonderfull answer....thanx alot..i'll try it first..thanx... =) |
|
| Back to top |
|
 |
rangana 500+ Club

Joined: 27 Feb 2008 Posts: 563 Location: Cebu City Philippines
|
Posted: Wed Jun 11, 2008 2:03 am Post subject: Re: Help me.....onblur () |
|
|
No problem, note that from the code i've given, you need not to assign onblur attribute in every input element. The script automatically loops through all the input box, except the last one which is for the submit.
If you're still stumped, get back  |
|
| Back to top |
|
 |
hazrizal84
Joined: 10 Jun 2008 Posts: 15
|
Posted: Wed Jun 11, 2008 2:13 am Post subject: Re: Help me.....onblur () |
|
|
| sir, may i have your yahoo messenger ID ?.. there is sumthing i need to discuss with u... |
|
| Back to top |
|
 |
rangana 500+ Club

Joined: 27 Feb 2008 Posts: 563 Location: Cebu City Philippines
|
Posted: Wed Jun 11, 2008 2:17 am Post subject: Re: Help me.....onblur () |
|
|
What's it?...I rarely give my YM. I'm having fair amount of spams already.
It's not that I don't trust you, but I don't want to risk. If you tell me via PM what you want, or post it in public, then I might be able to weight it and give you my YM. |
|
| Back to top |
|
 |
hazrizal84
Joined: 10 Jun 2008 Posts: 15
|
Posted: Wed Jun 11, 2008 2:24 am Post subject: Re: Help me.....onblur () |
|
|
oo..alrite...
bout the question i asked, i just allow the user to key in their answer in number or just let it be a slash for unknown answer.. i don want user to mix up number and slash in a given space, even they might be able to key in a slash. let's say, if a user try to key in the answer like : 43/21.. you see, there is a slash in the answer. so i don want that. when he/she key in 43/21 and press tab to move on to the next textbox, it will appear the error message box, state that, user has key in both number and slash.. u get my prob?.. looking 4ward for your answer.. thanx alot .. |
|
| Back to top |
|
 |
rangana 500+ Club

Joined: 27 Feb 2008 Posts: 563 Location: Cebu City Philippines
|
Posted: Wed Jun 11, 2008 2:34 am Post subject: Re: Help me.....onblur () |
|
|
How about this modification instead:
| Code: |
<script type="text/javascript">
window.onload=function()
{
var inps=document.getElementsByTagName('input');
for(var i=0;i<inps.length-1;i++)
{
inps[i].onblur=function()
{
if(this.value.indexOf('/')!=-1&&(this.value.length>1))
{
alert('Answers should either be number or slash only!\nNo Combination Please.');
}
}
}
}
</script>
|
|
|
| Back to top |
|
 |
hazrizal84
Joined: 10 Jun 2008 Posts: 15
|
Posted: Wed Jun 11, 2008 2:38 am Post subject: Re: Help me.....onblur () |
|
|
| ok..that's wat i want..thanx alot sir...thanx 4 ur help..is anythng, can i ask u again?.. |
|
| Back to top |
|
 |
rangana 500+ Club

Joined: 27 Feb 2008 Posts: 563 Location: Cebu City Philippines
|
Posted: Wed Jun 11, 2008 2:50 am Post subject: Re: Help me.....onblur () |
|
|
| Yes. I could help, if I can. |
|
| Back to top |
|
 |
hazrizal84
Joined: 10 Jun 2008 Posts: 15
|
Posted: Wed Jun 11, 2008 3:52 am Post subject: Re: Help me.....onblur () |
|
|
sir, i've prob again....sory 4 disturbing u...
just wanna know, how can we modify the codes if we want the cursor to highlight the wrong answer after the error message box been popped up?..can u help me?..use the select() key rite?..but i don know how.. |
|
| Back to top |
|
 |
rangana 500+ Club

Joined: 27 Feb 2008 Posts: 563 Location: Cebu City Philippines
|
Posted: Wed Jun 11, 2008 3:57 am Post subject: Re: Help me.....onblur () |
|
|
| Code: |
<script type="text/javascript">
window.onload=function()
{
var inps=document.getElementsByTagName('input');
for(var i=0;i<inps.length-1;i++)
{
inps[i].onblur=function()
{
if(this.value.indexOf('/')!=-1&&(this.value.length>1))
{
alert('Answers should either be number or slash only!\nNo Combination Please.');
this.style.background='#fc0'; //replace with the color you wish
}
}
}
}
</script>
|
|
|
| Back to top |
|
 |
hazrizal84
Joined: 10 Jun 2008 Posts: 15
|
Posted: Wed Jun 11, 2008 4:27 am Post subject: Re: Help me.....onblur () |
|
|
no sir..that's not what i mean...
after the message box appeared, i want to highligth the answer keyed in by user..so that, he/she can make the correction for that answer..the cursor wil remain at the answer keyed in, without move to the next textbox. |
|
| Back to top |
|
 |
|