/    Sign up×
Community /Pin to ProfileBookmark

Javascript works in firefox but not in IE

Please HELP.

The following script works perfectly in FireFox, But not in IE

[CODE]<script type=”text/javascript” >
function populate(inForm)
{
var temp=0;
var today= new Date();
var day= today.getDate();
var month= today.getMonth();
var year= today.getFullYear();
t2= 50;
for (var i=0; i <31 ; i++)
{
var x= String(i+1);

inForm.day.options[i] = new Option(x,x);
}

for (var i=0; i <31 ; i++)
{
var d=0;
d=inForm.day.options[i].value;
if(d=day){
inForm.day.options[i].selected=true;
break;}
}

for (var i=0,j=year; i <t2 ; i++, j–)
{
var y= String(j);
inForm.year.options[i] = new Option(y,y);

}
for(var i=0;i<12;i++)
{

if(i=month)
{inForm.month.options[i].selected=true;
break;}

}

}

function populate2(inForm2)
{
var t3=0;

if(inForm2.month.options[1].selected)

t3=28;
else if(inForm2.month.options[8].selected||inForm2.month.options[3].selected||inForm2.month.options[5].selected||inForm2.month.options[10].selected)
t3=30;
else
t3=31;

for(i=0;i<31;i++){
inForm2.day.options[i]=null;
}

for (var i=0; i <t3 ; i++)
{
var x= String(i+1);
inForm2.day.options[i] = new Option(x);

}
}
</script>

<style type=”text/css”>
<!–
.style1 {
color: #000099;
font-weight: bold;
}
.style2 {color: #FF0000}
–>
</style>

</HEAD>

<BODY onLoad=populate(form1)>

<div align=”center” class=”style1″>
<div align=”center”>NAC Member Number Search</div>
</div>
<br>
<div align=”left”>Select your Date of Birth from Drop Down, First Name and Last Name to search for NAC Member No.</div>
<form name=’form1′ action=’process_form.php’ method=’POST’>
<table class=’table_form_1′ id=’table_form_1′ cellspacing=’0′>
<tr>
<p>
<b>Year</b><SELECT NAME=”year”></SELECT>

<b>Month</b> <SELECT NAME=”month” onChange = populate2(form1)>
<Option value=1>01</Option>
<Option value=2>02</Option>
<Option value=3>03</Option>
<Option value=4>04</Option>
<Option value=5>05</Option>
<Option value=6>06</Option>
<Option value=7>07</Option>
<Option value=8>08</Option>
<Option value=9>09</Option>
<Option value=10>10</Option>
<Option value=11>11</Option>
<Option value=12>12</Option>
</SELECT>

<b>Day</b> <SELECT NAME=”day”></SELECT>

</FORM>

</td>
</tr>
<tr>
<td class=’ftbl_row_2′ ><LABEL for=’firstName’ ACCESSKEY=’none’ ><b style=’color:red’>*</b>First Name
</td>
<td class=’ftbl_row_2a’ ><input type=’text’ name=’firstName’ id=’firstName’ size=’20’ value=”>
</td>
</tr>
<tr>
<td class=’ftbl_row_1′ ><LABEL for=’lastName’ ACCESSKEY=’none’ ><b style=’color:red’>*</b>Last Name
</td>
<td class=’ftbl_row_1a’ ><input type=’text’ name=’lastName’ id=’lastName’ size=’45’ value=”>
</td>
</tr>
<tr>
<td colspan=’2′ align=’right’><input type=’submit’ name=’submit’ value=’Submit’>&nbsp;<input type=’reset’ name=’reset’ value=’Reset’><br /><a</a>
</td>
</tr>
</table>
</form>[/CODE]

to post a comment
JavaScript

17 Comments(s)

Copy linkTweet thisAlerts:
@KorJul 13.2007 — I doubt it works even in FF...

At a first glance, two errors:
<i>
</i>...
if(d=[COLOR="Red"]=[/COLOR]day)
...

&lt;body onload=populate([COLOR="Red"]document['form1'][/COLOR])&gt;
...
Copy linkTweet thisAlerts:
@Bob1660authorJul 13.2007 — It definitely works in FF
Copy linkTweet thisAlerts:
@KorJul 13.2007 — It definitely works in FF[/QUOTE]
You [I]think[/I] it works, but I assure you that is [I]not[/I] working.

If you know javascript so good, I guess you need not our adivices, do you? :rolleyes:

  • 1. [B]if()[/B] conditioner needs a Boolean evaluation. The assignment (x=y) will not return a Boolean. For a Boolean evaluation you need a comparison (x==y).


  • 2. in the event handler:


  • onload=populate(form1)

    form1 (as it is written) should be a global variable. But there is no global variable set as form1 in your code.

    So, that, in my opinion, there are 2 sets of problems which will prevent your code from working in any browser, FF included...

    Furthermore, open your FF Error console, and you will see some of the errors by yourself
    Copy linkTweet thisAlerts:
    @Bob1660authorJul 13.2007 — KOR,

    Thank you for your valuable feedback. I am an absolute NOVICE with javascript (only been using for 2 weeks), and I am not trying to sound obnoxious when I said that it works in FF (it really does work). Thank u for the Boolean evaluation explanation, I have rectified that and it works PROPERLY now. I do not fully understand your reply <body onload=populate(document['form1'])>. Can u please explain the "document" in the statement. Once again, THANK U very much, and I apologize if I sounded obnoxious.
    Copy linkTweet thisAlerts:
    @SparoHawkJul 13.2007 — The document object is used to reference and manipulate the content of the current page. Exactly how the page is accessed depends on the Document Object Model that the browser uses. This is not a reserved word so you can declare your own variable or function called document but if you do then you will not be able to reference anything on the current web page.[/QUOTE]

    That's a dictionary definition xD.

    document contains methods to access and manipulate HTML elements. You can create, remove, copy, refer to, etc.

    document can also let you instantly access some elements on the fly. Especially forms and links (a).

    Since your form has the name 'form1', you can access it directly with document['form1']. The reason for this is that your function populate() expects an object reference, inForm, not a string.

    Your onload has populate(form1), but form1 is not a defined variable much less an object.
    Copy linkTweet thisAlerts:
    @Bob1660authorJul 14.2007 — <i>
    </i>&lt;script type="text/javascript" &gt;
    function populate(inForm)
    {
    var temp=0;
    var today= new Date();
    var day= today.getDate();
    var month= today.getMonth();
    var year= today.getFullYear();

    t2= 50;
    for (var i=0; i &lt;31 ; i++)
    {
    var x= String(i+1);

    <i> </i>inForm.day.options[i] = new Option(x,x);
    <i> </i>}

    for (var i=0; i &lt;31 ; i++)
    {
    var d=0;
    d=inForm.day.options[i].value;
    if(d==day){
    inForm.day.options[i].selected=true;
    break;}
    }

    for (var i=0,j=year; i &lt;t2 ; i++, j--)
    {
    var y= String(j);
    inForm.year.options[i] = new Option(y,y);

    <i> </i>}
    for(var i=0;i&lt;12;i++)
    {

    <i> </i>if(i=month)
    <i> </i> {inForm.month.options[i].selected=true;
    <i> </i>break;}

    <i> </i>}

    }

    function populate2(inForm2)
    {
    var t3=0;


    if(inForm2.month.options[1].selected)

    t3=28;
    else if(inForm2.month.options[8].selected||inForm2.month.options[3].selected||inForm2.month.options[5].selected||inForm2.month.options[10].selected)
    t3=30;
    else
    t3=31;


    for(i=0;i&lt;31;i++){
    inForm2.day.options[i]=null;
    }

    for (var i=0; i &lt;t3 ; i++)
    {
    var x= String(i+1);
    inForm2.day.options[i] = new Option(x);

    <i> </i>}
    }
    &lt;/script&gt;

    &lt;style type="text/css"&gt;
    &lt;!--
    .style1 {
    color: #000099;
    font-weight: bold;
    }
    .style2 {color: #FF0000}
    --&gt;
    &lt;/style&gt;

    &lt;/HEAD&gt;

    &lt;BODY onLoad=populate(document["form1"])&gt;

    &lt;div align="center" class="style1"&gt;
    &lt;div align="center"&gt;NAC Member Number Search&lt;/div&gt;
    &lt;/div&gt;
    &lt;br&gt;
    &lt;div align="left"&gt;Select your Date of Birth below and enter your First Name and Last Name to search for your NAC Member No.&lt;/div&gt;
    &lt;form name='form1' action='process_form.php' method='POST'&gt;
    &lt;table class='table_form_1' id='table_form_1' cellspacing='0'&gt;
    &lt;tr&gt;
    &lt;p&gt;
    &lt;b&gt;Year&lt;/b&gt;&lt;SELECT NAME="year"&gt;&lt;/SELECT&gt;

    &lt;b&gt;Month&lt;/b&gt; &lt;SELECT NAME="month" onChange = populate2(form1)&gt;
    &lt;Option value=1&gt;01&lt;/Option&gt;
    &lt;Option value=2&gt;02&lt;/Option&gt;
    &lt;Option value=3&gt;03&lt;/Option&gt;
    &lt;Option value=4&gt;04&lt;/Option&gt;
    &lt;Option value=5&gt;05&lt;/Option&gt;
    &lt;Option value=6&gt;06&lt;/Option&gt;
    &lt;Option value=7&gt;07&lt;/Option&gt;
    &lt;Option value=8&gt;08&lt;/Option&gt;
    &lt;Option value=9&gt;09&lt;/Option&gt;
    &lt;Option value=10&gt;10&lt;/Option&gt;
    &lt;Option value=11&gt;11&lt;/Option&gt;
    &lt;Option value=12&gt;12&lt;/Option&gt;
    &lt;/SELECT&gt;

    &lt;b&gt;Day&lt;/b&gt; &lt;SELECT NAME="day"&gt;&lt;/SELECT&gt;

    &lt;/FORM&gt;

    <i> </i> &lt;/td&gt;
    <i> </i>&lt;/tr&gt;
    <i> </i>&lt;tr&gt;
    <i> </i> &lt;td class='ftbl_row_2' &gt;&lt;LABEL for='firstName' ACCESSKEY='none' &gt;&lt;b style='color:red'&gt;*&lt;/b&gt;First Name
    <i> </i> &lt;/td&gt;
    <i> </i> &lt;td class='ftbl_row_2a' &gt;&lt;input type='text' name='firstName' id='firstName' size='20' value=''&gt;
    <i> </i> &lt;/td&gt;
    <i> </i>&lt;/tr&gt;
    <i> </i>&lt;tr&gt;
    <i> </i> &lt;td class='ftbl_row_1' &gt;&lt;LABEL for='lastName' ACCESSKEY='none' &gt;&lt;b style='color:red'&gt;*&lt;/b&gt;Last Name
    <i> </i> &lt;/td&gt;
    <i> </i> &lt;td class='ftbl_row_1a' &gt;&lt;input type='text' name='lastName' id='lastName' size='45' value=''&gt;
    <i> </i> &lt;/td&gt;
    <i> </i>&lt;/tr&gt;
    <i> </i>&lt;tr&gt;
    <i> </i> &lt;td colspan='2' align='right'&gt;&lt;input type='submit' name='submit' value='Submit'&gt;&amp;nbsp;&lt;input type='reset' name='reset' value='Reset'&gt;&lt;br /&gt;&lt;a&lt;/a&gt;
    <i> </i> &lt;/td&gt;
    <i> </i>&lt;/tr&gt;
    &lt;/table&gt;
    &lt;/form&gt;
    Copy linkTweet thisAlerts:
    @SparoHawkJul 14.2007 — Try this one out:

    Very minor changes, specifically if statements where you had left-hand assignments instead of comparisons.

    [upl-file uuid=f26d8c0e-dab0-4e8e-87d9-6a1259d48cbe size=3kB]js2.txt[/upl-file]
    Copy linkTweet thisAlerts:
    @Bob1660authorJul 14.2007 — With changes STILL only works in FF and NOT in IE
    Copy linkTweet thisAlerts:
    @SparoHawkJul 14.2007 — Really, I don't know what is wrong with your browser. I tested that script in 4 different browsers and the dates get filtered perfectly when you choose the month.

    I tested it in:

    Mozilla Firefox 2.0.0.4

    Internet Explorer 6

    Internet Explorer 7

    Opera 9.10
    Copy linkTweet thisAlerts:
    @Bob1660authorJul 14.2007 — SparowHawk,

    You are right, the dates filter down with NO problem, but nothing happens on the submit or rest buttons.
    Copy linkTweet thisAlerts:
    @Bob1660authorJul 14.2007 — Sorry did not mentioned that the submit and reset buttons works in FF and not in IE
    Copy linkTweet thisAlerts:
    @Bob1660authorJul 14.2007 — I should have explained that the submit and reset buttons works in FF and not in IE. With FF you can reset entries, and the submit button fires off the process_form.php script. IE however does nothing on both buttons.

    Hope this helps
    Copy linkTweet thisAlerts:
    @SparoHawkJul 14.2007 — AHhhhhhh, now you are talking. U.U Try to be more precise in your explanations plz.

    Even I missed this: Look at this part:

    [CODE]<b>Month</b> <SELECT NAME="month" onChange = populate2(form1)>
    <Option value=1>01</Option>
    <Option value=2>02</Option>
    <Option value=3>03</Option>
    <Option value=4>04</Option>
    <Option value=5>05</Option>
    <Option value=6>06</Option>
    <Option value=7>07</Option>
    <Option value=8>08</Option>
    <Option value=9>09</Option>
    <Option value=10>10</Option>
    <Option value=11>11</Option>
    <Option value=12>12</Option>
    </SELECT>

    <b>Day</b> <SELECT NAME="day"></SELECT>

    </FORM>

    </td>
    </tr>
    <tr>
    <td class='ftbl_row_2' ><LABEL for='firstName' ACCESSKEY='none' ><b style='color:red'>*</b>First Name
    </td>[/CODE]


    Notice the </FORM> tag? You are ending the form too prematurely. Eliminate that line that closes the form and it will work in IE.
    Copy linkTweet thisAlerts:
    @Bob1660authorJul 14.2007 — SparowHawk,

    You are THE BEST.

    Thanks very much for all the assistance. I have been staring at the code for to long. This has been a very good learning experience, with excellent advice.

    Thanks SparowHawk
    Copy linkTweet thisAlerts:
    @KorJul 15.2007 — if(i=[COLOR="Red"]=[/COLOR]month)
    Copy linkTweet thisAlerts:
    @bathurst_guyJul 15.2007 — It's a good idea to indent your code so you will easily find silly mistakes like that.
    Copy linkTweet thisAlerts:
    @Bob1660authorJul 16.2007 — Problem Resolved
    ×

    Success!

    Help @Bob1660 spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 5.17,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @AriseFacilitySolutions09,
    tipped: article
    amount: 1000 SATS,

    tipper: @Yussuf4331,
    tipped: article
    amount: 1000 SATS,

    tipper: @darkwebsites540,
    tipped: article
    amount: 10 SATS,
    )...