By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,784 Members | 3,582 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,784 IT Pros & Developers. It's quick & easy.

fireEvent - return false - Won't do it.

P: 3
I am testing out an idea for an IE7 only user base.

The idea is that there are a bunch of Input fields on a form. Each field validates itself "onblur" like so. I want logically should be able to use "fireEvent" to fire the onblur (or any other event) of any given input obj.

fireEvent returns true or false depending on the success of the event firing. I think I have my event carry through screwed up. any help would be appriciated. My problem is that even though the the return is false in either function, obj.fireEvent('onblur') returns "true".
Expand|Select|Wrap|Line Numbers
  1. <div id=divOfInputs>
  2. <input type=text id=txtFirstInput name=WindowInputs onblur="Input_OnBlur(this);"><br>
  3. <input type=text id=txtFirstInput name=WindowInputs onblur="Input_DoThis(this);"><br>
  4. <input type=button id=btnSubmit onclick="Submit();">
  5. </div>
  6.  
js.....................

Expand|Select|Wrap|Line Numbers
  1. function Input_OnBlur(obj)
  2. {    var answer = false;
  3.     window.event.returnValue = return answer;
  4. }
  5. function Input_DoThis(obj)
  6. {    var answer = false;
  7.     return answer;               
  8. }
  9. function Submit()
  10. {    var theInputs = document.getElementById('divOfInputs').getElementsByTagName('input');
  11. for (var i = 0; i < theInputs.length; i++)
  12. {    if (theInputs[i].name == "WindowInputs")
  13.     {var e = window.event;
  14.                  var theResult = theInputs[i].fireEvent('onblur', e);        
  15.      alert("theInputs of " + i + " is " + theResult);
  16.        // this always alerts true, even though the event function is returning or set to false.
  17.                 }
  18. }
  19. }
  20.  
Can anyone point out my flaw, I think my issue is in which event the fireEvent is reporting on. Thanks

Don
Sep 21 '07 #1
Share this Question
Share on Google+
5 Replies


P: 3
a further note.

I am aware that clicking the the submit button causes the current field to blur. however I need a false result of that blur to cause the submit function to halt.

The goal is to make sure that when the user clicks submit all the fields are validated. Without knowing which one the user will be on I am forced to validate all the inputs, if any is false the then the submit JS does not proceed to the action portion (AJAX call that writes date to the DB)

I have a working version where in I give the different inputs different names based on thier validator and call thier respective onblur fuctions dirrectly instead of through the event and read the result, but this is messy and just bad code, every time I add a new validation I would have to come back and update the submit code for that new case. makes me cringe.

Don
Sep 21 '07 #2

pbmods
Expert 5K+
P: 5,821
Heya, Don. Welcome to TSDN!

Please use CODE tags when posting source code:

[CODE=javascript]
JavaScript code goes here.
[/CODE]
Sep 21 '07 #3

acoder
Expert Mod 15k+
P: 16,027
I don't use fireEvent, but based on the documentation it seems as though you can't get a value of false.

Why not use normal form validation techniques whether the user base is IE7-only or not? Look at the form validation links in the Offsite Links thread.
Sep 23 '07 #4

P: 3
As I read the MSDN docs I don't believe you are correct. FireEvent can return false if the event can. The docs say:

"If the event being fired cannot be cancelled, fireEvent always returns true. "

What this means, and a table listing which events can and cannot be canceled, I just can't find. It would seem I can cancel the blur event if I call the input_dothis function dirrectly.

My Validation Scheme:
1. OnBlur check for validation against very large datalist on server using AJAX, giving active feedback to user as they fill in the fields.
2. OnSubmit recall the onblur JS for each field on the form, causing the onblur AJAX check to happen again. (Necessary becuase the last field on blur will not stop the Submit if it fails.)
3. Validate on server the info provided in the form.


Basically I need to know what event can be canceled, and in what situation I can cause fire event to return false.

The alternative work around I am working on right now creates global Array which stores the result of the onblur function on keys of the inputID and can be recalled after the fireevent to determine whether to continue or not.

DWB
Sep 24 '07 #5

acoder
Expert Mod 15k+
P: 16,027
My Validation Scheme:
1. OnBlur check for validation against very large datalist on server using AJAX, giving active feedback to user as they fill in the fields.
2. OnSubmit recall the onblur JS for each field on the form, causing the onblur AJAX check to happen again. (Necessary becuase the last field on blur will not stop the Submit if it fails.)
3. Validate on server the info provided in the form.
You don't need fireEvent for this. Just call the Ajax function onblur (consider using onchange to avoid unnecessary calls).

Use the form onsubmit event handler to stop the form being submitted. Perhaps you could set a variable to false if any of the validation has failed so far.
Sep 25 '07 #6

Post your reply

Sign in to post your reply or Sign up for a free account.