Click to See Complete Forum and Search --> : Can you submit a form to a function?


desdub
04-17-2003, 06:54 AM
Hi,

Is there any way to define a form's Action so that the form is handled by a javascript function within the page rather than an external link? I know the following doesn't work (and probably doesn't make sense) but it is kinda what I'm trying to achieve.

<form action="myFunction(document.myForm)" method=get/put? name="myForm">
blah blah blah
</form>

Thanks for looking

D.

tim_gor
04-17-2003, 07:16 AM
Yes you can handle the form using the page's javascript.

Your form tag should say:

<form action="javascript:myFunction(...)">
... (form elements)
</form>

tim_gor
04-17-2003, 07:18 AM
Alternatively you could just use
<form name="...">
</form>

without any ACTION attribute -- in this case just don't have a "submit" button as such, use a regular button (or a graphic) and have the action on that set to "javascript:myfunction()"

desdub
04-17-2003, 07:21 AM
Thanks Tim,

I like the first option better 'cause it should also handle a RETURN key press.

D.

desdub
04-17-2003, 07:34 AM
Actually,

Tim, it didn't work.

But thanks Dave, what you said did work.

This was my first question to this forum and it wont be my last!

Thanks again.

D.