/    Sign up×
Community /Pin to ProfileBookmark

check box help please

hi

i have a group of check boxes on a form for the user to select their residential status.

they have six choices and if they choose homeowner (the value of this field is o) they have to enter the value of property and amount of mortgage.

heres my code

if (theForm.m_res_status.value == “O”)

then

if ((theForm.m_value_of_prop.value ==””) ||
(theForm.m_amount_of_mortgage.value ==””))
{

alert(“Please enter the value of your property and the amount of mortgage”)
theForm.m_value_of_prop.focus()
return false;

}

i have also tryed

if (theForm.m_res_status(0).checked == true)
then

if ((theForm.m_value_of_prop.value ==””) ||
(theForm.m_amount_of_mortgage.value ==””))
{

alert(“Please enter the value of your property and the amount of mortgage”)
theForm.m_value_of_prop.focus()
return false;

}

but both of them make the value of property and amount of mortgage mandatory even if an option other than homeowner is selected ?

thanks for any help

cheers ThisAndThat

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@ThisAndThatauthorApr 05.2004 — i seem to have got it to work using

if ((theForm.m_res_status(0).checked == false) ||

(theForm.m_res_status(1).checked == true) ||

(theForm.m_res_status(2).checked == true) ||

(theForm.m_res_status(3).checked == true) ||

(theForm.m_res_status(4).checked == true) ||

(theForm.m_res_status(5).checked == true))

then

if ((theForm.m_value_of_prop.value =="") ||
(theForm.m_amount_of_mortgage.value ==""))
{

alert("Please enter the value of your property and the amount of mortgage")
theForm.m_value_of_prop.focus()
return false;

}


if anyone has a better way that you can do this please feel free to let me know.

thanks ThisAndThat
Copy linkTweet thisAlerts:
@steelersfan88Apr 05.2004 — I've always enclosed them in brackets instead, but if not, you could generate that condition, such as:[code=php]var finStr = new String;
for(var i=0;i<6;i++) {
finStr += (i==0)?"(!theForm.m_res_status(0).checked":"theForm.m_res_status("+ i +").checked"
finStr += (i<5)?") || (":")"
}[/code]
Then check the condition with:if(eval(finStr))which is much shorter than your current condition ?
Copy linkTweet thisAlerts:
@ThisAndThatauthorApr 06.2004 — thanks for that steelersfan88. when i get a free minute i think i'll have a play with your code.

thanks ThisAndThat
Copy linkTweet thisAlerts:
@steelersfan88Apr 06.2004 — sure, have a go ?
×

Success!

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