[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

How to capture the destination element?

Posted on 2005-05-06
9
Medium Priority
?
622 Views
Last Modified: 2013-11-19
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
0
Comment
Question by:ramsharma23
8 Comments
 
LVL 6

Expert Comment

by:superm401
ID: 13947860
Try an onChange event.  It won't be fired for a script-based change.
0
 
LVL 15

Expert Comment

by:SnowFlake
ID: 13948099
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
 

Author Comment

by:ramsharma23
ID: 13948469
Can u please send the code snippet...
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 25

Expert Comment

by:devic
ID: 13950736
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
 
LVL 15

Expert Comment

by:SnowFlake
ID: 13953022
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
 

Author Comment

by:ramsharma23
ID: 13967258

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
 
LVL 15

Accepted Solution

by:
SnowFlake earned 2000 total points
ID: 13975298
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
 
LVL 17

Expert Comment

by:Cem Türk
ID: 15697231
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

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
A while back, I ran into a situation where I was trying to use the calculated columns feature in SharePoint 2013 to do some simple math using values in two lists. Between certain data types not being accessible, and also with trying to make a one to…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

872 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question