/    Sign up×
Community /Pin to ProfileBookmark

form onsubmit two functions

Hi, I´m new to this forum. I hope that I can find help here.

Attached is a zip file with my code. Sorry, html text and comments are in spanish.

I´m trying to create this calculator witch is basically a form that when submit, result will appear at the bottom inside a div witch is currently hidden with css.

I have set the onsubmit event equal to a function that validates the form fields. This first function is based on one I learn at lynda.com

If the first function returns true, it means that all fields are ok. But the browser window refresh and clears all the values. i think that at this point is my problem.

A second function is supposed to do a calculation based on the fields values and reveal a hidden div for the answer.

After that I need to return false, so the window dose not refresh.

Please take a look at my code

[upl-file uuid=a614dcb6-f1bf-4326-b45d-f72a4b16c45a size=14kB]calculadora.zip[/upl-file]

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@efficaciousOct 02.2008 — ok i didn't look at your code. and I'll tell you why..

I'm not about to download a random zip file to my pc from a forum.

N2m these forums are setup to allow you to post code in a clean fashion so there is no need for the .zip file.


So without looking at your code i've come to this conclusion.

You need to run two functions once the "Submit" button is clicked.

So very simple

Example (JUST AN EXAMPLE)

JS:
<i>
</i>&lt;script&gt;
function firstfunction()
{
//DISPLAY DIV
}

function secondfunction()
{
//DO CALCULATIONS

//AFTER CALCULATIONS FINISH

firstfunction();
}


&lt;/script&gt;


then for you html/form code:

[CODE]<form action='' method=''>
<input type='button' id='Submit' value='Calculate!' onmousedown='secondfunction();' />
</form>[/CODE]



and thats pretty much all it.

Just don't setup the form to actually be a form.. hell you don't even really need the form tags. Since your never really submitting the data but rather using the input values for a javascript function. There is not a need to have an actual submitting process happen.

welp i hope that helps..

`eff
Copy linkTweet thisAlerts:
@chiste_gmail_coauthorOct 02.2008 — Hi Eff

Thanks for your replay. After posting this tread I find out how to solve it. Luckily you didn't download my zip file. After resolving my problem with my first function I notice that the second function return a lot of NAN in the hidden div.

I'd tried to include my code inside my post, but there was a number of characters limit.

ZIP file was an easy way to post my files.

I'll post the finished product URL soon.
×

Success!

Help @chiste_gmail_co spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...