On Wed, Jul 8, 2009 at 3:08 PM, Nathan Chen <[email protected]> wrote:
>
> I wonder if I missed something when I mixed JavaScript code with CFInput
> tag. Please see my code below. I placed the "required" and "message" in
> cfinput. It works fine. But I need to search the user input string and
> find if certain value exists, e.g "something". Since I don't know how to
> do it in CF, I created a JS. The problem is that it rolls to the next
> page(meaning submits the form) rather than return false.
> --------------------------------------------------------
>
> <script language="javascript">
>
> function check ()
> {
>
> var e = document.forms[0].s.value.toLowerCase();
>
> if (e.match("something") == null)
> {
> alert("You have to type the word SOMETHING.")
> document.forms[0].s.focus();
> return false;
> }
> }
> </script>
>
> <cfform action="t4.cfm" method="post">
> <cfinput name="s" size="20" required="yes" message="Please enter
> something.">
> <cfinput name="submit" type="submit" value=" Go " onClick="check()">
> </cfform>
>
One of the reasons I stopped using cfform many many years ago is that it
often interfered with my own JS.
With that disclaimer out of the way...
remove the 'onclick' from your submit. change your <cfform> tag to this:
<cfform action="t4.cfm" method="post" onsubmit="return check();">
you might also want to add an "else" into your check() function to return
true.
--
I have failed as much as I have succeeded. But I love my life. I love my
wife. And I wish you my kind of success.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Want to reach the ColdFusion community with something they want? Let them know
on the House of Fusion mailing lists
Archive:
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:324361
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4