/    Sign up×
Community /Pin to ProfileBookmark

Help with kind of validator

Hello, first post here…

This script isn’t working how I want it to – please if you can offer suggestions / help – it would be greatly appreciated!

[CODE]<script type=”text/javascript”>
function match() {

var typefield = document.getElementById(type);
var catidfield = document.getElementById(categoryid);

if((typefield.value == ‘Print’) && (catidfield.value == ’30’)) {
alert(“You must select a print category”);
return false;
}
if((typefield.value != ‘Print’) && (catidfield.value != ’30’)){
alert(“You must select ‘No Category’ for this Type”);
return false;
}
return true;
}
</script>[/CODE]

Being called from this form…

[CODE]<form id=”JobTicket” action=”Entering/enteringjob.php” method=”post” name=”JobTicket” onsubmit=”return job.exec(); return match()”>[/CODE]

No troubles with job.exec – only with match.

Thanks in advance ?

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@KorMar 04.2008 — [B]match[/B] is a javascript reserved word (it is a javascript RegExp method) Name your function otherwise, let's say Match() or whichever...
Copy linkTweet thisAlerts:
@ErinellaauthorMar 04.2008 — Thanks Kor - I renamed the function as suggested and this did not solve the problem.

Need more help - is my syntax for the && expression accurate?

Will it ever return false to display the alert box such that the user can fix their problem??
Copy linkTweet thisAlerts:
@MindstormsKidMar 04.2008 — It looks like you need to add some [I]} else {[/I] and [I]} else if () {[/I] things:

[code=html]<script type="text/javascript">
function matchIt() {

var typefield = document.getElementById(type);
var catidfield = document.getElementById(categoryid);

if (typefield.value == 'Print' && catidfield.value == '30') {
alert("You must select a print category");
return false;
} else if (typefield.value != 'Print' && catidfield.value != '30') {
alert("You must select 'No Category' for this Type");
return false;
} else {
return true;
}
}
</script>

<form id="JobTicket" action="Entering/enteringjob.php" method="post" name="JobTicket" onsubmit="return job.exec(); return matchIt()">[/code]

That might work.
Copy linkTweet thisAlerts:
@ErinellaauthorMar 05.2008 — Hi all - this has been resolved thanks to Orc Scorcher from a previous thread:

http://www.webdeveloper.com/forum/showthread.php?t=73684&highlight=multiple+onsubmit

Thanks to everyone ?
×

Success!

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