/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] Javascript in Internet Explorer

I have a simple Javascript code which I tried running on Internet explorer but was unable to . The same code runs on Mozilla Firefox. I have a lot of such code which does not run on the explorer. Can anyone please let me know if Javascript is browser specific and what can I do to make the Javascript code compatible with all browsers ? As I have already done the complete coding for my project I won’t be able to change it to make it browser compatible using libraries like JQuery etc so could you please suggest some simple way to solve the issue..

Enclosing sample code

JAVASCRIPT CODE

[CODE] <script type=”text/javascript”>
function fillvalues()
{
if (checkbox1.checked == true)
value1 = 1;
else
value1=0;

var input1= document.getElementById(‘page_1’);
input1.setAttribute(‘value’,value1);
alert(input1.value);

if (checkbox2.checked == true)
value2 = 1;
else
value2=0;

var input2= document.getElementById(‘page_2’);
input2.setAttribute(‘value’,value2);
alert(input2.value);

}

</script>[/CODE]

[CODE]<INPUT type=”checkbox” id=”checkbox1″ >
<INPUT type=”checkbox” id=”checkbox2″ >
<INPUT type=”hidden” id=”page_1″ name=”page1″ />
<INPUT type=”hidden” id=”page_2″ name=”page2″ />

<INPUT type=”button” name=”Submit” value=”Continue” onclick=”fillvalues()”/>

[/CODE]

This code works perfectly in mozilla but not in IE . It gets stuck in the line checkbox.checked.

Would greatttlllyyyy appreciate your help

Thanks in advance

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@ZeroKilledDec 02.2007 — i had tried the sample in firefox 1.5, ie7 and ie6. they work fine for me althought the script is buggy. your script access input element calling the id on the global scope without using the proper function. for example, you have the reference checbox1 and checkbox2 as object. because this two name are ids you should call them with the function document.getElementById as you did for page_1 and page_2 ids. is likely that this practice lead to error, hence is considered bad practice.
Copy linkTweet thisAlerts:
@ruchi_bhindwaleauthorDec 02.2007 — Thanks a lot for the input. Once I got a reference to the checkbox using getElementbyId I could print the values but I am facing a lot of issues with the different browsers . Is javascript browser dependant ? Certain code that runs well in mozilla doesnot work in IE .. Can you suggest any solution for this?

For example this code runs well in Mozilla but it gives error in Internet Explorer.

I am getting the value of the variable B from a php statement like this

<?php

$B=$_GET["B"];

?>

The javacript function gets called whenever the user presses the submit button and according to the value of B which is a number the particular if case is executed, but it not executed in the IE. When I commented out the <?php echo "$B" ?> statement in the javascript it started working .

JAVASCRIPT CODE

[CODE]
function showMethod()
{
var y = (<?php echo "$B" ?>);
if(y == 1)
alert("1");
else if(y == 2)
alert("2");
else
alert("Some other number");
}[/CODE]



<form>

<input type="button" onclick="showMethod()">

</form>

It gives an error in the showMethod on the where I am running the php code in the javascript function.

Could you please let me know what the error is ?

Thanks again
Copy linkTweet thisAlerts:
@FangDec 02.2007 — Compatible webpages

The code does run correctly in IE
×

Success!

Help @ruchi_bhindwale 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 6.18,
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: @nearjob,
tipped: article
amount: 1000 SATS,

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

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...