How to capture the destination element?

Hi,
     I have a jsp consisting of a count.This count is a text box against which there are two buttons(say "+" and "-" buttons)
In this, if the count value is invalid/ (or on the basis of some condition), i throw an error in the onblur event of the text box. And the page is displayed along with the error message. At the same time, if i  click on the "+" button, the count has to be incremented and the error message should not be displayed. but this also comes under the onblur event of the text box.

   how to differentiate the two actions? Is there any way to capture the "+" or the "-" button the user has clicked onblur event of the textbox.
   How to handle this in javascript? Since both fall under the same event "onblur", it is very difficult to differentiate.
   It would be very much helpful if anyone could give me the solution for this? I need the solution immediately
ramsharma23Asked:
Who is Participating?
 
SnowFlakeConnect With a Mentor Commented:
I am not sure I understand what event exactly you are trying to catch.

you can use the following code to view the events that are fired while handleing
the select element

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title></title>
</head>
<body>

<select id="sel" name="sel">
<option>opt1</option>
<option>opt2</option>
<option>opt3</option>
</select>
<br>
<textarea id="ta" name="ta" style="width:500px;height:500px;"></textarea>

<script language="javascript">

for (pr in document.all.sel) {
 if (pr.substring(0,2)=='on') {
      document.all.ta.value = pr+'\n' + document.all.ta.value;
      funcBody=new Array();
      i=0;
      funcBody[i++]='if (\'onmousemove\'.indexOf(\'' + pr + '\') == -1) {';
      funcBody[i++]='document.all.ta.value=\'' +  pr + ' fired\\n\' + document.all.ta.value';
      funcBody[i++]='}';
      document.all.sel[pr]= new Function('',funcBody.join('\n'));;
 }
}
document.all.ta.value = '------------------------\n' + document.all.ta.value ;      
</script>

</body>
</html>

If this will not help you, I suggest that you open a new Q as you will be more likely to draw new expertes and get a fast answer.

SnowFlake
0
 
superm401Commented:
Try an onChange event.  It won't be fired for a script-based change.
0
 
SnowFlakeCommented:
You could in your event handler use window.setTimeout
that will actually do the actual validation in half a second
you save the returned handle from the window.setTimeout
in some global variable.
then in your + / - you can use window.clearTimeout to prevent the validation
from happning at all.

If you want exact code, just say so.

SnowFlake
0
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

 
ramsharma23Author Commented:
Can u please send the code snippet...
0
 
devicCommented:
ramsharma23 show your code, or do some example that doesn't work, I can not get your problem.

maybe this:
=========================================
<script>
function c(obj)
{
      var cn=obj.form.supeNumber
      obj.value=="+"?cn.value++:cn.value--;
      checkit(cn);
}
function checkit(obj)
{
      if(obj.value<5 || obj.value>10)
      {
            alert("error: select number between 5 & 10");
      }
}
</script>
<form>
      <input onclick=c(this) type=button value=->
      <input type=text name=supeNumber onblur=checkit(this) value=5>
      <input onclick=c(this) type=button value=+>
</form>
0
 
SnowFlakeCommented:
If I understood the Q correctly ramsharma23
wants that if he sets the code to be 4 for example and then uses the + button to increment it all the way upto
11 fast enough (I know thats a dubious term) then assuming both 4 and 11 are leagal numbers it will not fire the error.

my Idea was (thanks to devic for supplying base code to use :) )


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<script>
var timerID;
timerID=0;

function c(obj)
{
     var cn=obj.form.supeNumber;
     obj.value=="+"?cn.value++:cn.value--;
     prepForCheck(cn);
}

function prepForCheck(cn){
     
     if (timerID != 0) window.clearTimeout(timerID);
     expr='checkit(' + cn.value + ');';
     timerID=window.setTimeout(expr,1000);

}

function checkit(value)
{
    if(value<5 || value>10) {
            return;
      }
    else
    {
          alert('' + value + ' is not a number less then 5 or above 10');
    }
}
</script>
</head>
<body>
<form ID="Form1">
     <input onclick=c(this) type=button value=- ID="Button1" NAME="Button1">
     <input type=text name=supeNumber onblur="prepForCheck(this);" value=5 ID="Text1">
     <input onclick=c(this) type=button value=+ ID="Button2" NAME="Button2">
</form>
</body>
</html>

which creates a "delayed" validation.

SnowFlake
0
 
ramsharma23Author Commented:

Hi Snow,

    This code works fine. Thanks a lot for the solution.
I have one more problem..
I wanted to perform an action whenever an option is selected is a drop down box.
What is the event that can be used to capture this???
I cannot use onchange because it gets fired only when there is any change in the option.
I wanted to know whenever user selects something in the select box, it can even be the same option selected again.

I tried onclick which doesn't work out as it gets fired many times when the user selects an option in select box....

Any quick solution please.....
0
 
Cem TürkSenior Software EngineerCommented:
No comment has been added to this question in more than 21 days, so it is now classified as abandoned.

I will leave the following recommendation for this question in the Cleanup topic area:
    Accept: SnowFlake

Any objections should be posted here in the next 4 days. After that time, the question will be closed.

cem_turk
EE Cleanup Volunteer
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.