/    Sign up×
Community /Pin to ProfileBookmark

onClick event problem

please could somebody tell me what I am doing wrong…I can’t seem to get it setaction(this.value) function to work with the same onClick event as return checkrequired(this) function

<SCRIPT LANGUAGE=”JavaScript”>
<!– Begin
function checkrequired(which) {
var pass=true;
if (document.images) {
for (i=0;i<which.length;i++) {
var tempobj=which.elements[i];
if (tempobj.name.substring(0,0)==””) {
if (((tempobj.type==”text”)&&
tempobj.value==”)||(tempobj.type.toString().charAt(0)==”s”&&
tempobj.selectedIndex==0)) {
pass=false;
break;
}
}
}
}
if (!pass) {
shortFieldName=tempobj.name.substring(2,60).toUpperCase();
alert(“Please Enter the Required Information for “+shortFieldName+” field.”);
//tempobj.focus();
return false;
}
else
return true;
}

function setaction(strVal){
if (strVal == “Click Here to SAVE FORM”){
document.device.action=”devicedatabaseform.asp”;
alert(“You are about to Save your Information”);
document.device.submit();
}
else if (strVal == “Click Here to SUBMIT FORM”){
document.device.action=”devicedatabaseform.asp”;
alert(“You are about to Submit your Information”);
document.device.submit();
}
else {
alert(“a error occured!”)
}
}

// End –>
</script>

response.write(” <input type=””submit”” name=””Action”” value=””Click Here to SUBMIT FORM”” onclick=””return checkrequired(this.form); parent.passDate(this.form.x_TESTDATE.value); setaction(this.value);””></td>”)

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@violent_jApr 27.2004 — maybe you could try to put the [b]return checkrequired(this.form);[/b] as the last argument in the onclick event

grtz
Copy linkTweet thisAlerts:
@joeloauthorApr 27.2004 — I tried putting the return checkrequired(this.form); as the last argument in the onclick event..it ran but will not return/hold for to make corrections b/4 submitting the form.
Copy linkTweet thisAlerts:
@violent_jApr 27.2004 — i can't really understand what you are trying to do with this construction i'd try it this way:

i would only use one function in the onclick event, which (if necessary) calls the other functions, set the desired action and eventually submits the form, or not. than you wouldn't be running around with strange errors/bugs because you've got it all in your own hand

grtz
Copy linkTweet thisAlerts:
@joeloauthorApr 27.2004 — Please I have a form with two submit buttons. Each to cause the user to do different thing (Save Form and Submit Form)

On clicking the SAVE Form Button...Information entered by the user is saved for editing later and On clicking

the SUBMIT Form Button...Information entered by the user is validated and submitted into the database


Response.Write "<form name=""device"" action=""devicedatabaseform.asp"" method=""post"">" & VbCrLf

...................................

..................................

...................................

response.write(" <td align=left><input type=""submit"" name=""SAVE"" value=""Click Here to SAVE FORM"" onclick=""parent.passDate(this.form.x_TESTDATE.value); setaction(this.value);""></td>")

response.write(" <input type=""submit"" name=""Action"" value=""Click Here to SUBMIT FORM"" onclick=""return checkrequired(this.form); parent.passDate(this.form.x_TESTDATE.value); setaction(this.value);""></td>")


response.write(" </form>")

thanks
×

Success!

Help @joelo 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,
)...