Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with If ... then .... else

Status
Not open for further replies.

ggrewe

IS-IT--Management
Jul 10, 2001
169
US
I have an order form that when a customer click this checkbox, I want to run the following onchange command. The if statement needs to check the value of the check box (0 or 1) and set the amount of the accordingly. If checked, then the value is $165, else then the value is 0.

Thanks in advance,

Greg

onchange= <%if (&quot;ActiveMember.value=1&quot;) then (&quot;ActiveMemberAmount.value=165&quot;)%>
<%else (&quot;ActiveMemberAmount.value=0&quot;) end if%>
 
Load this page in your browser and see if that's what you're looking for.
Code:
<html>
<head>
<script Language=&quot;JavaScript&quot;>
<!--
function setValue(form_ref) {
  if(form_ref.ActiveMember.checked) {
    form_ref.ActiveMemberAmount.value = &quot;$165.00&quot;
  } else {
    form_ref.ActiveMemberAmount.value = &quot;$0.00&quot;
  }
}
//-->
</script>
</head>
<body>
<form name=&quot;myForm&quot;>
<input type=&quot;checkbox&quot; name=&quot;ActiveMember&quot; onClick=&quot;setValue(this.form);&quot;>Active Member</input><br>
<input type=&quot;text&quot; name=&quot;ActiveMemberAmount&quot;>
</form>
</body>
</html>

ToddWW
 
You could do this in a client-side javascript.

Code:
<form name=membersRSVP>

<input type=checkbox name=&quot;activeMember&quot; onclick=&quot;calculateCharge()&quot;> Active Members check here.
<input type=hidden name=&quot;activeMemberAmount&quot; value=0>
<input type=submit>
</form>

etc.

<script>
function calculateCharge(){
   if(document.membersRSVP.activeMember.checked == true)
      document.membersRSVP.activeMemberAmount.value = 165;
   else
      document.membersRSVP.activeMemberAmount.value = 0;
}
</script>

I used onclick instead of onchange because Netscape does not recognize onchange.
 
ToddWW

I see where you are going with this, but I am having a hard time making it work with my existing form. There are over 15 fields with this same problem that I need to address. Can I e-mail the form to you, make one change so that it works and I will finish from there?

Greg
greg@grewe.d2g.com
 
Sure.
sendpage@fuelaccess.com

Explain what you want to do with the other fields.

ToddWW
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top