By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,326 Members | 2,726 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,326 IT Pros & Developers. It's quick & easy.

Help in referencing object

P: n/a
Hi All,

I'm not a javascript programmer, but I'm trying to accomplish something
here that is not working.

I have 2 buttons on an HTML form, along with several text fields. If
Button #1 is clicked, I only want to validate some of the text fields,
if Button #2 is clicked, I want to check them all.

I'm having trouble referencing the button name that was clicked.
Snippets of my code is below, if someone can help me please.

Thanks

..
..
..
<script language="javascript">
function validate(thisform) {
with (thisform)
if (thisform.action.value == "Duplicate") {
if (emptyvalidation(subject,"Subject is empty")==false)
{subject.focus(); return false;}
}
if (thisform.action.value == "Save") {
if (emptyvalidation(subject,"Subject is empty")==false)
{subject.focus(); return false;}
if (datevalidation(PartyDate,"Please select a valid Date")==false)
{PartyDate.focus(); return false;};
if (valButton(party_domain) == null) {alert('No Party Location
selected'); return false;};
if (isOneCheckboxChecked(thisform) == false) {alert('No List
Selected'); return false;};
}}
..
..
..
<FORM NAME='NEW_MENU' ACTION='sched.pl' METHOD=POST onsubmit="return
validate(this)">
..
..
..
<input type='submit' name='action' VALUE='Duplicate'
onclick="validate(this);">
<input type='submit' name='action' VALUE='Save'
onclick="validate(this);">
..
..
..

Jan 24 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
VK

am****@iwc.net wrote:
Hi All,

I'm not a javascript programmer, but I'm trying to accomplish something
here that is not working.

I have 2 buttons on an HTML form, along with several text fields. If
Button #1 is clicked, I only want to validate some of the text fields,
if Button #2 is clicked, I want to check them all.

I'm having trouble referencing the button name that was clicked.
Snippets of my code is below, if someone can help me please.


"submit" event for form contains form itself as target / srcElement, so
this approach won't fly. Thinking of the minimum code change: you can
use mouseup instead for buttons (maybe not what W3C would like to see,
but it works)

<script type="text/javascript">
var chosenAction = "";

function validate(f) {
if (chosenAction == "Duplicate") {
if (emptyvalidation(f.subject,"Subject is empty")==false)
{f.subject.focus(); return false;}
}
if (chosenAction == "Save") {
if (emptyvalidation(f.subject,"Subject is empty")==false)
{f.subject.focus(); return false;}
if (datevalidation(f.PartyDate,"Please select a valid Date")==false)
{f.PartyDate.focus(); return false;}
if (valButton(f.party_domain) == null)
{alert('No Party Location selected'); return false;}
if (isOneCheckboxChecked(f) == false)
{alert('No List Selected'); return false;}
}
}

<FORM NAME='NEW_MENU' ACTION='sched.pl' METHOD=POST
onsubmit="return validate(this)">

<input type='submit' name='action' VALUE='Duplicate'
onmouseup="chosenAction=this.value">
<input type='submit' name='action' VALUE='Save'
onmouseup="chosenAction=this.value">

Jan 25 '06 #2

P: n/a
I like this modular code approach. I'll try and implement it and let
you know.

Honestly tought, I do not understand what you mean when you say "Don't
validate in the onclick handler of the submit element".

I'm not a good object programmer.......so if you can explain, that'd be
helpful.

Jan 25 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.