Hi everyone, I am proud of myself, I am finally finish. It took me too weeks working with this day and night, but I am finally finish. The only thing is that I have a bug in my code.

I have a getbyelement section that has the visibility to be shown when CreditCardInfo is true. It works fine when I click on credit card but the problem is that it does NOT hide when I click on other selections beside credit card.

Therefore, I tried this and the credit card selection is still displaying even when I choose another option like check or cash.

function CheckForCreditCard(el)
{
	if (el.options[2].selected == true)
	{ 
	var CreditCardInfo = document.getElementById("CreditCardInfo");
	CreditCardInfo.style.visibility = "visible";
	}
	else
	if (el.options[2].selected == false)
	CreditCardInfo.style.visibility = "hidden";
}


  <strong>Payment:</strong>
  <select name="selPayment" onchange="CheckForCreditCard(this);">
    <option value="Cash" selected="selected">Cash</option>
    <option value="Check">Check</option>
    <option value="Credit Card" >Credit Card</option>
  </select>
  
  <div id="CreditCardInfo"> <br />
    Card Number:
    <input name="selCreditCardInfo" size="20" type="text" />&nbsp;&nbsp; Month:
    <input type="text" name="txtMonth" size="4" />&nbsp;&nbsp;Year:
    <input name="txtYear" size="4" type="text" />
  </div>

Recommended Answers

All 2 Replies

Again silly mistake. You have define

var CreditCardInfo = document.getElementById("CreditCardInfo");

inside the if-block and u are using it in else-block.

define

var CreditCardInfo = document.getElementById("CreditCardInfo");

above if-block.

function CheckForCreditCard(el)
{
                var CreditCardInfo = document.getElementById("CreditCardInfo");
	if (el.options[2].selected == true)
	{ 
	                     CreditCardInfo.style.visibility = "visible";
	}
	else
	if (el.options[2].selected == false)
	CreditCardInfo.style.visibility = "hidden";
}

Thank you very much for your help. I continue telling myself it looks right why is it not working. Not thinking that it mater where my variable statement was. I thank you very much. Now I understand to put all my variable strings underneath the functions. I also like how you break it down and explain. Because I am a beginner and I am trying to get the understanding of why we do certain things in javascript.
Luckychap you rock!

Again silly mistake. You have define

var CreditCardInfo = document.getElementById("CreditCardInfo");

inside the if-block and u are using it in else-block.

define

var CreditCardInfo = document.getElementById("CreditCardInfo");

above if-block.

function CheckForCreditCard(el)
{
                var CreditCardInfo = document.getElementById("CreditCardInfo");
	if (el.options[2].selected == true)
	{ 
	                     CreditCardInfo.style.visibility = "visible";
	}
	else
	if (el.options[2].selected == false)
	CreditCardInfo.style.visibility = "hidden";
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.