Go Back   DeveloperBarn Forums > Programming & Scripting > JavaScript Programming

Sponsored Links

Discuss "drop down problem" in the JavaScript Programming forum.

JavaScript Programming - Javascript is a cross-browser client-side scripting language. Discuss Javascript and AJAX related scripts here.


Reply « Previous Thread | Next Thread »
 
LinkBack Thread Tools Display Modes
  #1  
Old June 30th, 2008, 11:13 AM
Barn Frequenter

 
Join Date: Mar 2008
Posts: 197
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 1
todd2006 is an unknown quantity at this point
Default drop down problem

Hi,

I have a drop down which has 3 values when one of them is selected I want to show content related to that value
in a div

when the page is first loaded I dont want to show any of the div's

Can someone tell me what i am doing wrong when the page is loaded first it displays the credit card div
and when i choose the options it doesnt give any error messages but it doesnt change the div's

Code:
<%

ReserveDisplaycredit = "none"
ReserveDisplaycash = "none"
ReserveDisplaycheck = "none"
%>

<select name="payway" id="payway" onChange="calloptionpay();">
<option value="">Select the Payment Type</option>
<option value="Cash">Cash</option>
<option value="Check">Check</option>
<option value="Credit Card">Credit Card</option>
</select>


<div id="reservecash" style="display: <%=ReserveDisplaycash%>;">
Cash
</div>

<div id="reservecheck" style="display: <%=ReserveDisplaycheck%>;">
check
</div>

<div id="reservecredit" style="display: <%=ReserveDisplaycredit%>;">
credit
</div>

function calloptionpay()
{
alert("hello");
var getpayway=document.frm1.payway.value;

alert(getpayway);

				
if(getpayway=="Cash")
{
hidecredit();
hidecheck();
changeDivcash('reservecash', 'block'); 
}
else if (getpayway=="Check")
{
hidecredit();
hidecash();
changeDivcheck('reservecheck', 'block'); 
}
else if (getpayway=="Credit Card")
{

hidecheck();
hidecash();
changeDivcredit('reservecredit', 'block'); 

}


}

function changeDivcash(the_div,the_change)
 {
	var the_style = getStyleObject(the_div);
	if (the_style != false)
		{
			the_style.display = the_change;
		}
  }

  function changeDivcredit(the_div,the_change)
 {
	var the_style = getStyleObject(the_div);
	if (the_style != false)
		{
			the_style.display = the_change;
		}
  }

  function changeDivcheck(the_div,the_change)
 {
	var the_style = getStyleObject(the_div);
	if (the_style != false)
		{
			the_style.display = the_change;
		}
  }


function hidecheck()
 {
	changeDivcheck("reservecheck", "none");
 }

 function hidecash()
 {
	changeDivcash("reservecash", "none");
 }

 function hidecredit()
 {
	changeDivcredit("reservecredit", "none");
 }
 
 function getStyleObject(objectId)
 { 
 	if (document.getElementById && document.getElementById(objectId))
 		{
 			return document.getElementById(objectId).style;
 		}
 	else if (document.all && document.all(objectId))
 		{
 		return document.all(objectId).style;
 		}
 	else
 		{
 		return false;
 		}
}
Reply With Quote
Sponsored Links
  #2  
Old June 30th, 2008, 11:17 AM
richyrich's Avatar
Moderator


 
Join Date: Mar 2008
Location: Somewhere only we know...
Posts: 395
Thanks: 26
Thanked 32 Times in 32 Posts
Blog Entries: 1
Rep Power: 1
richyrich will become famous soon enough

Awards Showcase
Classic ASP JavaScript 
Total Awards: 2

Default

Try putting your functions in <script></script> tags.
Code:
<script language="Javascript type="text/Javascript">
function whatever()
.
.
.
.
end function
 
function anotherfunction()
.
.
.
.
end function
</script> 
Hope that helps.
Reply With Quote
  #3  
Old June 30th, 2008, 11:29 AM
Barn Frequenter

 
Join Date: Mar 2008
Posts: 197
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 1
todd2006 is an unknown quantity at this point
Default

Hi,

I have it in the script tags on my page. Did you mean to include script tags in the post

todd
Reply With Quote
  #4  
Old June 30th, 2008, 11:49 AM
richyrich's Avatar
Moderator


 
Join Date: Mar 2008
Location: Somewhere only we know...
Posts: 395
Thanks: 26
Thanked 32 Times in 32 Posts
Blog Entries: 1
Rep Power: 1
richyrich will become famous soon enough

Awards Showcase
Classic ASP JavaScript 
Total Awards: 2

Default

I meant in your page. If you have them in <script> tags, that's fine.

Change:-
Code:
var getpayway=document.frm1.payway.value;
to:-
Code:
var sel_payway = document.getElementById("payway")
var getpayway = sel_payway.options[sel_payway.selectedIndex].text
I can't see why the credit card info appears on page load. Maybe trying viewing the html source from the browser and see what's being rendered to the screen.

Hope that helps.
Reply With Quote
  #5  
Old June 30th, 2008, 12:27 PM
Barn Frequenter

 
Join Date: Mar 2008
Posts: 197
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 1
todd2006 is an unknown quantity at this point
Default

I tried it same thing it shows the div for credit card
Code:
<div id="reservecash" style="display: none;">
Cash
</div>

<div id="reservecheck" style="display: none;">
check
</div>

<div id="reservecredit" style="display: none;">
credit 
</div>
the above is what i see when i do a view source
Reply With Quote
  #6  
Old June 30th, 2008, 12:36 PM
richyrich's Avatar
Moderator


 
Join Date: Mar 2008
Location: Somewhere only we know...
Posts: 395
Thanks: 26
Thanked 32 Times in 32 Posts
Blog Entries: 1
Rep Power: 1
richyrich will become famous soon enough

Awards Showcase
Classic ASP JavaScript 
Total Awards: 2

Default

The code I posted related to your JS function for the OnChange event.

I'm still uncertain why the divs don't all hide.
Reply With Quote
  #7  
Old June 30th, 2008, 12:40 PM
Barn Frequenter

 
Join Date: Mar 2008
Posts: 197
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 1
todd2006 is an unknown quantity at this point
Default

yes the biggest problem is when the page is loaded why does it show the credit card div

Is there a different way of doing it
Reply With Quote
  #8  
Old June 30th, 2008, 01:17 PM
richyrich's Avatar
Moderator


 
Join Date: Mar 2008
Location: Somewhere only we know...
Posts: 395
Thanks: 26
Thanked 32 Times in 32 Posts
Blog Entries: 1
Rep Power: 1
richyrich will become famous soon enough

Awards Showcase
Classic ASP JavaScript 
Total Awards: 2

Default

I just tried the same and it worked fine. All the divs were hidden.

Could you post the whole code so I can see how it's structured?
Reply With Quote
  #9  
Old June 30th, 2008, 03:35 PM
Barn Frequenter

 
Join Date: Mar 2008
Posts: 197
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 1
todd2006 is an unknown quantity at this point
Default

here is the code

Code:
<%
Option Explicit
Dim ReserveDisplaycredit, ReserveDisplaycash, ReserveDisplaycheck


ReserveDisplaycredit = "none"
ReserveDisplaycash = "none"
ReserveDisplaycheck = "none"

Response.write "ReserveDisplaycredit:-" & ReserveDisplaycredit & "<br/>"
Response.write "ReserveDisplaycash" & ReserveDisplaycash & "<br/>"
Response.write "ReserveDisplaycheck" & ReserveDisplaycheck & "<br/>"

%>
<head>
<title>Main</title>

<script type="text/javascript">
<!--
function getStyleObject(objectId)
{ 
	if (document.getElementById && document.getElementById(objectId))
		{
			return document.getElementById(objectId).style;
		}
	else if (document.all && document.all(objectId))
		{
		return document.all(objectId).style;
		}
	else
		{
		return false;
		}
}

function calloptionpay()
{
var sel_payway = document.getElementById("payway")
var getpayway = sel_payway.options[sel_payway.selectedIndex].text
alert(getpayway);

			
if(getpayway=="Cash")
{
alert("are we here");
hidecredit();
hidecheck();
changeDivcash('reservecash', 'block'); 
}
else if (getpayway=="Check")
{
hidecredit();
hidecash();
changeDivcheck('reservecheck', 'block'); 
}
else if (getpayway=="Credit Card")
{

hidecheck();
hidecash();
changeDivcredit('reservecredit', 'block'); 

}


}

function changeDivcash(the_div,the_change)
 {
	var the_style = getStyleObject(the_div);
	if (the_style != false)
		{
			the_style.display = the_change;
		}
  }

  function changeDivcredit(the_div,the_change)
 {
 alert("change credit");
	var the_style = getStyleObject(the_div);
	if (the_style != false)
		{
			the_style.display = the_change;
		}
  }

  function changeDivcheck(the_div,the_change)
 {
  alert("change check");
	var the_style = getStyleObject(the_div);
	if (the_style != false)
		{
			the_style.display = the_change;
		}
  }


function hidecheck()
 {
  alert("hide check");
	changeDivcheck("reservecheck", "none");
 }

 function hidecash()
 {
	changeDivcash("reservecash", "none");
 }

 function hidecredit()
 {
 alert("hide credit");
	changeDivcredit("reservecredit", "none");
 }


//form Validation ends 
// -->
</script>

</head>
<body>

<form name="frm1" id="frm1" method="post"  action="confirm.asp"> 


<table>


<td>Payment Method:</td>
<td><select name="payway" id="payway" onChange="calloptionpay();">
<option value="">Select the Payment Type</option>
<option value="Cash">Cash</option>
<option value="Check">Check</option>
<option value="Credit Card">Credit Card</option>
</select>
</td>
</tr>

<div id="reservecash" style="display: <%=ReserveDisplaycash%>;">
Cash
</div>

<div id="reservecheck" style="display: <%=ReserveDisplaycheck%>;">
check
</div>


<div id="reservecredit" style="display: <%=ReserveDisplaycredit%>;">
credit
</div>

<%
Response.write "ReserveDisplaycredit:-" & ReserveDisplaycredit & "<br/>"
Response.write "ReserveDisplaycash" & ReserveDisplaycash & "<br/>"
Response.write "ReserveDisplaycheck" & ReserveDisplaycheck & "<br/>"

%>


</body>
</html>
Reply With Quote
  #10  
Old June 30th, 2008, 05:25 PM
richyrich's Avatar
Moderator


 
Join Date: Mar 2008
Location: Somewhere only we know...
Posts: 395
Thanks: 26
Thanked 32 Times in 32 Posts
Blog Entries: 1
Rep Power: 1
richyrich will become famous soon enough

Awards Showcase
Classic ASP JavaScript 
Total Awards: 2

Default

I copied your code exactly and it worked fine for me in IE6 and FF 2.

However, if that was the whole code, you are missing the following tags:-
<html>
<tr>
</table>
</form>

Maybe sorting these out will solve your problem.
Reply With Quote
Reply

  DeveloperBarn Forums > Programming & Scripting > JavaScript Programming

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
display problem with drop downs todd2006 JavaScript Programming 3 May 5th, 2008 05:31 PM
drop down problem todd2006 .Net Development 2 April 23rd, 2008 11:37 AM


All times are GMT -4. The time now is 05:58 PM.



Content Relevant URLs by vBSEO 3.2.0