[thelist] OnBlur and CFIF together?

Jeff jeff at members.evolt.org
Sat Jul 22 13:42:43 CDT 2000


palyne,

:~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
: From: Palyne Gaenir <palyne at sciencehorizon.com>
:
: I'm looking for some kind of "generic" onBlur script
: that in the header, will only do function and would
: allow me to insert the CF code of my choice to be
: executed inside (where the onBlur is used -- not
: in the head) -- is this possible??
:~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

cold fusion is executed server-side by the application server.  so, there
would be no way for a form element to execute client-side some cf code when
a form element is blurred.

:~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
: Essentially I want some kind of simple universal
: script that I can put on every form field that will do
: whatever I need including checking length of entries
: in textareas, last three chars of FileNames in a file
: upload field, and so forth.
:~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

i can see how you might think a universal script would have some advantages.
however, the file size alone of something that would cover every situation
would be monumental.  you're also not likely to find that universal script
all finished, you'd have to keep adding to it as you found things you
needed.

:~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
: I saw references recently made on another CF list
: related to this kind of JS (but not including CF code
: inside of course!) and I went and downloaded .js
: and explanatory files... but ye gods....  must all
: this js stuff be SO complicated??
:~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

does all cf look so complicated to you?  if you could recognize the various
javascript functions and their purpose it would be much easier to
understand.

:~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
: Since CF can do form validation AFTER a form is
: submitted by doing IF statements looking for various
: things in important fields, I'm looking for a way to use
: both the js onBlur and CF code to do all the validation
: IN the form.  Possible??
:~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

the javascript would have to perform all the validation client-side and then
allow the form to submit.  then, as a backup you'd have to recreate all that
validation logic, except in cf this time, to perform the validation again
server-side.  that's as close as you can get to combining the two.

:~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
: Failing this, has anyone the simple (I once had it!) js
: for textarea length-check onBlur... one that is generic
: in head and allows different settings within form field
: (for multiple uses of it in one form)...?
:~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

i write this stuff all day long.  i build validation routines for each and
every form we process information for.  this should do what you want:

<script language="JavaScript" type="text/javascript">
  <!--
    function maxlength(obj,len)
    {
      if(obj.value.length > len)
      {
        // this alert() is on one line.
        alert('The maximum number of characters this field will accept is '
+ len + ' characters.\nIt currently contains ' + obj.value.length + '.
Please remove at least ' + (obj.value.length - len) + ' characters.');
        // this alert() is on one line.
        obj.focus();
      }
    }
  // -->
</script>

you would then call this function like this:

<textarea onChange="maxlength(this,1000)">

notice i'm not using the onBlur event handler?  that's because it makes
sense to put the cursor back in the field that needs to be fixed, but when
you do this with an onBlur event you run the risk of two onBlur validated
fields with non-valid data fighting over the cursor resulting in an endless
loop of alert()s.

:~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
: Anybody have any ideas?
:~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

this is going to sound kinda obvious, but my  suggestion is to learn some of
the basics of javascript cause you're going to be using it all the time.

good luck,

.jeff

name://jeff.howden
game://web.development
http://www.evolt.org/
mailto:jeff at members.evolt.org





More information about the thelist mailing list