Ezilon.com - Target Your Audience, be Seen in Your Region

Javascript works in Firefox, not in IE

You are viewing this site as a guest. Join our community to get your questions answered and share knowledge. Active members may advertise and ask for a website critique.

They have: 16 posts

Joined: May 2006

I'm having problems with a javascript, and I think its something simple that I'm missing. I tried researching and messing with it, but I could not find anything.

Basically, its a drop down menu to choose times, but they are only allowed to choose a time between 8am and 8pm. When you click on the hour, it changes the AM/PM dropdown to what it could be and disables it. It will be displayed more than once on a page, so it sends a variable called num to differentiate between different times. I tested it in firefox, and it works fine but in IE(6 & 7) it does not do anything.

Thank you for your help!

<script type="text/javascript">
//time fix
function fixtimes(num) {
var x = document.getElementById("time"+num+"a");//        am/pm
var t = document.getElementById("time"+num+"h").value;//  hour
if (t == 8 ) { //set to am and enable
x.selectedIndex= 0;
x.disabled =false;
} else if (t >= 9 && t <= 11) {//set to am and disable
x.selectedIndex = 0;
x.disabled =true;
} else if (t == 12 || (t >= 1 && t <= 7)){ //set to pm
x.selectedIndex = 1;
x.disabled =true;
} else { //should not happen
x.disabled =false;
}
}
&lt;/script&gt;

<p>Time 1:</p>
<select name="time1h" id="time1h" onChange="return fixtimes('1')">
<option selected></option>
<option >1</option>
<option >2</option>
<option >3</option>
<option >4</option>
<option >5</option>
<option >6</option>
<option >7</option>
<option >8</option>
<option >9</option>
<option >10</option>
<option >11</option>
<option >12</option>
</select>
<select name="time1a" id="time1a" >
<option selected>a.m.</option>
<option >p.m.</option>
</select>

JeevesBond's picture
Moderator

He has: 3,489 posts

Joined: Jun 2002

You need to add a value attribute to all those options, for example:

      <option value="1">1</option>
      <option value="2">2</option>
      <option value="3">3</option>

Am attaching a working version of your code. The problem is that Internet Explorer won't use the text inside an <option></option> tag, the option="x" has to be included. Most other browsers work correctly, including Firefox and Opera.

AttachmentSize
index.html1.67 KB

a Padded Cell our articles site!

They have: 16 posts

Joined: May 2006

Yep, that was it. I knew it was something simple that I was over looking.
Thank you!

JeevesBond's picture
Moderator

He has: 3,489 posts

Joined: Jun 2002

No problem, silly Internet Explorer! Smiling

They have: 88 posts

Joined: May 2008

All the Moderators and Admins here are helpful, Very good.
I shall recommend this place to friends and their friends. (LOL)

It really is a shame that people use Internet Explorer instead of Firefox.

Why does IE act diffrently with code to the others browsers?

Best Wishes,
Mike
www.rsdarkness.com