User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the JavaScript / DHTML / AJAX section within the Web Development category of DaniWeb, a massive community of 375,236 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,021 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JavaScript / DHTML / AJAX advertiser: Lunarpages Web Hosting
Views: 415 | Replies: 2
Reply
Join Date: Feb 2008
Posts: 2
Reputation: CathInfo is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
CathInfo CathInfo is offline Offline
Newbie Poster

Help What am I overlooking? Totally stumped!

  #1  
Feb 28th, 2008
var s = document.getElementById('field[12]');
var cust_cc_exp_month = s.options[s.selectedIndex].value;

// This displays the correct Value -- which is "0" for item #0 = "Please select..."
alert("Month: " + cust_cc_exp_month.toString());
if (cust_cc_exp_month == "0") {
  // This code never executes!
}

Here is the HTML portion:

<select id="field[12]" name="field[12]">
<option value="0">MONTH</option>
<option value="1" <?php if ($field[12] == "1") echo "SELECTED" ?>>January</option>
<option value="2" <?php if ($field[12] == "2") echo "SELECTED" ?>>February</option>
<option value="3" <?php if ($field[12] == "3") echo "SELECTED" ?>>March</option>
</select>


I've tried using cust_cc_exp_month.toString(), and I've tried == 0 instead of == "0".
Nothing seems to work. To me, it defies all logic! There has to be something I'm overlooking.

Thanks for any help you can provide --

Matthew
Last edited by CathInfo : Feb 28th, 2008 at 12:10 pm.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jan 2007
Posts: 2,433
Reputation: MidiMagic is on a distinguished road 
Rep Power: 6
Solved Threads: 99
MidiMagic's Avatar
MidiMagic MidiMagic is offline Offline
Nearly a Posting Maven

Re: What am I overlooking? Totally stumped!

  #2  
Mar 1st, 2008
Are you putting string values into field[12] ?
Daylight-saving time uses more gasoline
Reply With Quote  
Join Date: Sep 2005
Posts: 611
Reputation: digital-ether will become famous soon enough digital-ether will become famous soon enough 
Rep Power: 5
Solved Threads: 38
Moderator
digital-ether's Avatar
digital-ether digital-ether is offline Offline
Practically a Master Poster

Help Re: What am I overlooking? Totally stumped!

  #3  
Mar 1st, 2008
I just tried this test:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
		<title>Untitled Document</title>
	</head>
	<body>
<script>
window.onload = function() {
	var s = document.getElementById('field[12]');
	var cust_cc_exp_month = s.options[s.selectedIndex].value;
	
	// This displays the correct Value -- which is "0" for item #0 = "Please select..."
	alert("Month: " + cust_cc_exp_month.toString());
	if (cust_cc_exp_month == "0") {
	  // This code never executes!
	  alert('ok');
	}
};

</script>

<select id="field[12]" name="field[12]">
<option value="0">MONTH</option>
<option value="1" <?php if ($field[12] == "1") echo "SELECTED" ?>>January</option>
<option value="2" <?php if ($field[12] == "2") echo "SELECTED" ?>>February</option>
<option value="3" <?php if ($field[12] == "3") echo "SELECTED" ?>>March</option>
</select>
	</body>
</html>

After the window loads, alert('ok'); is executed as expected. I tested in FF2.0 and IE6,7.

I don't see how you could be having the problem you're having unless you have a JavaScript error somewhere thats preventing full execution of the JS.

a conditional such as:
if (cust_cc_exp_month == "0") 

is equivalent to:

if (cust_cc_exp_month == false) 

or

if (!cust_cc_exp_month) 

since type's are not being evaluated.

If you had

if (cust_cc_exp_month === "0") 

then the type would matter and an Integer 0 would be differentiated from the string '0' or the boolean false.
www.fijiwebdesign.com - web design and development and fun
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb JavaScript / DHTML / AJAX Marketplace
Thread Tools Display Modes

Other Threads in the JavaScript / DHTML / AJAX Forum

All times are GMT -4. The time now is 4:20 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC