/    Sign up×
Community /Pin to ProfileBookmark

Help on Java If Statement

I need to check a form for input. I need it to check if values are in a certain range and if they are I need to have them enter two more values. I found that I need to check if the the two more values are actually there also.

here is the code:

<– START SCRIPT –>

function checkform() {

var str = document.levels.mac.value;

if (document.levels.ctxpwr.value == “”) {
alert(“Enter TX Level”);
return(false);
}
if (document.levels.crxpwr.value == “”) {
alert(“Enter RX Level”);
return(false);
}
if (document.levels.csnr.value == “”) {
alert(“Enter SNR Ratio”);
return(false);
}
if (str.length < 12) {
alert(“MAC Address needs to be 12 Characters”);
return(false);
}
if (!(document.levels.ctxpwr.value == “”) && document.levels.ctxpwr.value < 36 || document.levels.ctxpwr.value > 50 && document.levels.taptx.value == “” || document.levels.taprx.value == “”) {
alert(“Failing Install – Please Enter Tap Values”);
return(false);
}
if (!(document.levels.crxpwr.value == “”) && document.levels.crxpwr.value > 10 || !(document.levels.crxpwr.value < -10) && document.levels.
taptx.value == “” || document.levels.taprx.value == “”) {
alert(“Failing Install – Please Enter Tap Values”);
return(false);
}
if (!(document.levels.csnr.value == “”) && document.levels.csnr.value < 30) && document.levels.taptx.value == “” || document.levels.taprx.value == “” {
alert(“Failing Install – Please Enter Tap Values”);
return(false);
}

return(true);

<– END SCRIPT –>

Problem is if the values are TRUE to out of spec then it doesnt Alert.

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@cbr929dudeauthorSep 09.2004 — solved it
Copy linkTweet thisAlerts:
@KorSep 09.2004 — You have not post the HTML code either. But I guess that you used an inproper event handler.

Anyway, the event handler must be [b]onsubmit[/b], and it must be placed in [b]form[/b] tag with a [b]return[/b] condition:

<form onsubmit="[color=red]return[/color] checkform()">

A remark... I think is a beter ideea to use classic boleean assignment, without brackets:

return [b]true[/b];

return [b]false[/b];
×

Success!

Help @cbr929dude 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 6.2,
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: @meenaratha,
tipped: article
amount: 1000 SATS,

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

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...