Closed Thread Icon

Topic awaiting preservation: Submitting a form based upon form-values (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=27308" title="Pages that link to Topic awaiting preservation: Submitting a form based upon form-values (Page 1 of 1)" rel="nofollow" >Topic awaiting preservation: Submitting a form based upon form-values <span class="small">(Page 1 of 1)</span>\

 
u-neek
Bipolar (III) Inmate

From: Berlin, Germany
Insane since: Jan 2001

posted posted 01-11-2006 21:10

Hi!

Let's assume we have the following two buttons:

code:
<input id="f_save" type="submit" name="submit" value="Save Changes"/>
<input id="f_delete" type="submit" name="submit" value="Delete Page"/>



Is it possible to call different javascript functions depending on the butten I've clicked on? If so, am i able to submit the form based on the return values (true or false)?

Sorry for asking dumb questions, but i'm still learning that javascript-thing.

Thanks.

u-neek
Bipolar (III) Inmate

From: Berlin, Germany
Insane since: Jan 2001

posted posted 01-11-2006 21:16

Let me append some details:

I have a form with a title- and a text-field. When clicking on the "Save Changes" button the javascript-function checks if the title-field is not empty.

When clicking on the "Delete page" button, the user must confirm, that he really wants to delete the page.

I think this could be done with done with only one function, but i don't know how to get the values of the button i've clicked on.

Tyberius Prime
Paranoid (IV) Mad Scientist with Finglongers

From: Germany
Insane since: Sep 2001

posted posted 01-11-2006 21:58

sure... just stick an onclick="return confirm('do you really want to do that?');" into the delete button.

if you return false in an onclick handler on a submit button, it's not being submited.
But to handle the enter key, you'll need to also capture the form's onsubmit.

Am I making sense?

bitdamaged
Maniac (V) Mad Scientist

From: 100101010011 <-- right about here
Insane since: Mar 2000

posted posted 01-12-2006 01:58

If you want the value of the button you can do something like this

code:
<input type="button" name="foo" value="bar" onclick="return validate(this)" />


function validate( b ) {
alert(b.value);
 //  all your code
}



This will alert "bar" so you can switch your test depending on what button you're on. (It seems two function s would be find but YMMV)




.:[ Never resist a perfect moment ]:.

(Edited by bitdamaged on 01-12-2006 01:59)

u-neek
Bipolar (III) Inmate

From: Berlin, Germany
Insane since: Jan 2001

posted posted 01-12-2006 21:25

Thanks for your help.

Here is what i've done with your help: http://www.ozoneasylum.com/27317

« BackwardsOnwards »

Show Forum Drop Down Menu