Flasher Archive

[Previous] [Next] - [Index] [Thread Index] - [Previous in Thread] [Next in Thread]


Subject: RE: FLASH: How to validate forms in action script????
From: Eric Dunham
Date: Sun, 12 Dec 1999 09:28:32 GMT

I'm not too familiar with ActionScript, but you could easily use a
JavaScript function to do what you are talking about.
Maybe something like:
---------------------------------------------------
function validate(DownPayment)
{
if (DownPayment.value.indexOf(',') != -1)
{
alert('Please check to make sure the DOWN PAYMENT field contains no
symbols or commas.');
//you could use the following code to go back to the form
//I'm not sure exactly how Flash handles forms as
//opposed to JavaScript because I'm relatively new
//to Flash, but if it's the same, then you can
//access the form field by
//document.forms[index].elements[index] or
//(this is what I prefer)
//document.myform.myelement
//but in that case you have to set the "name="
//attribute for the form and the elements
DownPayment.focus();
return false;
}
else
{
return true;
}
}
---------------------------------------------------
Seeing as how I don't know a whole helluva lot about forms and Flash, I
can't really help you there. But you can easily pass the value of the Flash
form field to a javascript function that checks to see if there is a comma
in the string. If you don't know what the JavaScript above does, I'll break
it down for you.
<explanation>
DownPayment.value.indexOf : the indexOf() method checks to see if the
character that is passed to the method exists within the string. So in this
case it checks to see if DownPayment.value has a comma in it. If the string
does not have a comma, it returns the value -1, and if it does contain the
specified character, it returns the position of the offending character in
the string. Now if you're already passing the value to the function you
don't have to use the .value property, I was just using that based on my
knowledge of HTML forms and the hierarchy of objects. In your case you could
just use DownPayment.indexOf(',');
DownPayment.focus() : if this is a supported method (the way that it is in
HTML), you simply put the cursor focus back in the DownPayment field for
them to enter a proper number. And if you find that it does support the
.focus() method then the form field probably also supports the "onBlur="
event handler, in which case you could call the validating code right after
they leave the box instead of having to wait until the user submits the
form.
return true/false : even though you probably already know what this means,
the return false; statement passes the boolean false value back to the
caller, in this case it would be your original if() statement. And the
return true; statement does the same thing :)
Additionally, you don't have to have the code all separated like that. In
fact, you don't even need the braces on the else statement. I just did that
for readability :)
</explanation>

Hope that helps,
Eric Dunham

<snip>
Ive spent five hours on this and I just cant find the answer. =(
Does anyone out there know this one?

Im trying to validate a field in a flash form at the "submit" button.
The number in the field can be any number, including zero, so long as
the number contains no commas. (Id really like to rule out all foreign
symbols but I wont press my luck).

Please note the "Else If (DownPayment)" line in the action script below.

On (Press)
If (DownPayment eq Chr(44))
Get URL ("javascript:AlertMsg("Please check to make sure
the DOWN PAYMENT field contains no symbols or
commas.")")
Else . . . . . blah blah {complete computation}
End If
End On
</snip>



flasher is generously supported by...
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Streaming Media WEST '99 Conference & Exhibition
"The Worlds largest Internet Audio & Video Event"
December 7 - 9, San Jose Convention Center, California

Reserve your space today at http://www.streamingmedia.com
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
To unsubscribe or change your list settings go to
http://www.chinwag.com/flasher or email helpatchinwag [dot] com


Replies
  RE: FLASH: How to validate forms in acti, Daniel Votino

[Previous] [Next] - [Index] [Thread Index] - [Next in Thread] [Previous in Thread]