Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

cfform onload

New Here ,
Jul 02, 2006 Jul 02, 2006
I would like to execute some javascript when a form is loaded. I don't know what i'm doing wrong.
Here is the code:

<head>
<script language="javascript">
function myalert()

{

alert("this is a test");

}
</script>
</head>


<!-------------------------------- THE FORM ----------------------------->
<!--- New drug form --->

<cfform action="drug_insert1.cfm" name="insertform" onload="myalert();">

<table>
<tr>
<td>Dose:</td>
<td>
<cfinput type="text"
name="Dose"
message="Drug Dose is required!"
required="yes"
validate="integer"
validateat="onsubmit,onserver"
size="10"
maxlength="10">
</td>
</tr>
<tr>
<a href="form_onload1.cfm">go here</a>
</tr>
</table>

</cfform>
2.1K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 02, 2006 Jul 02, 2006
Do it on the <body> tag instead.

<body onload="myalert();">

--
Ken Ford
Adobe Community Expert


"suluclac" <webforumsuser@macromedia.com> wrote in message
news:e89c28$45u$1@forums.macromedia.com...
>I would like to execute some javascript when a form is loaded. I don't
>know
> what i'm doing wrong.
> Here is the code:
>
> <head>
> <script language="javascript">
> function myalert()
>
> {
>
> alert("this is a test");
>
> }
> </script>
> </head>
>
>
> <!-------------------------------- THE FORM ----------------------------->
> <!--- New drug form --->
>
> <cfform action="drug_insert1.cfm" name="insertform" onload="myalert();">
>
> <table>
> <tr>
> <td>Dose:</td>
> <td>
> <cfinput type="text"
> name="Dose"
> message="Drug Dose is required!"
> required="yes"
> validate="integer"
> validateat="onsubmit,onserver"
> size="10"
> maxlength="10">
> </td>
> </tr>
> <tr>
> <a href="form_onload1.cfm">go here</a>
> </tr>
> </table>
>
> </cfform>
>


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 02, 2006 Jul 02, 2006
Thank you Ken, that worked!
I still don't understand why the other way doesn't work, though.

-Gary
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 03, 2006 Jul 03, 2006
LATEST
I still don't understand why the other way doesn't work, though.
You are right to expect the onLoad event to fire when cfform loads. The Coldfusion cfform documentation tells us onLoad will fire when the format attribute is set to HTML or XML.

It apparently doesn't. I believe that the onLoad attribute is redundant. After all, it is absent from the list of attributes for the form element in the current HTML v4.01 specifications.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 02, 2006 Jul 02, 2006
Gary,

If you want to add something to the form use onsubmit:

<cfform action="drug_insert1.cfm" name="insertform" onsubmit="myalert();">

That way it will run when you click the submit button.

--
Ken Ford
Adobe Community Expert


"suluclac" <webforumsuser@macromedia.com> wrote in message
news:e89gis$95i$1@forums.macromedia.com...
> Thank you Ken, that worked!
> I still don't understand why the other way doesn't work, though.
>
> -Gary


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources