Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
JavaScript Errors in Firefox and Safari
Old 08-04-2008, 06:48 PM JavaScript Errors in Firefox and Safari
Novice Talker

Posts: 8
Trades: 0
Hi!

I'm new to scripting (though I've had experience with programming and graphics). For my first site, I'm having problems with JavaScript in Firefox and Safari.

It seems that JavaScript works fine for normal functions, it launches the "confirm" box and all... but whenever I try to use JavaScript to change a value of an item that does not belong to the same function, an error is generated. Strangely, these errors are only generated in Firefox and Safari. The script works fine in Internet Explorer and Opera.

For example, if I use this code, it doesn't work:
Code:
<head>
    <title>Untitled Page</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<!-- nameClick() function definition -->
<script type="text/javascript">
function nameClick(nm)
{
    var name1 = nm;
    Button1.value = "Clicked!";  //Does not work in Firefox and Safari
}
</script>
</head>
<body>
    <input onclick="nameClick('Hello')" id="Button1" type="submit" value="nameClick" />
</body>
You might say there is a flaw in my code, but the same is true for codes right out of MSDN's online help. Take a look at this code. Same problem.

Code:
<head>
<script type="text/jscript">

function CookieGroup() 
{
txtOutput.value = window.event.srcElement.value;
}
</script>
</head>

<body>

<!-- Controls are grouped by giving them the same NAME but unique IDs. -->
<p>Grouped Radio Buttons<br>
<input type="radio" 
    name="rdoTest" 
    id="Cookies" 
    value="accept_cookies" 
    checked 
    onclick="CookieGroup()"><br>
<input type="radio" 
    name="rdoTest" 
    id="NoCookies" 
    value="refuse_cookies" 
    onclick="CookieGroup()"><br>
</p>
<p>Ungrouped Radio Button<br>
<input type="radio" 
    name="rdoTest1" 
    value="chocolate-chip_cookies" 
    onclick="CookieGroup()"><br>
</p>
<p>Value of control on which the onclick event has fired<br>
<textarea name="txtOutput" style="width: 250px"></textarea> </p>

</body>
So does anyone know WHY this happens? Is there any known way to fix this?

Thanks!

Last edited by uttaresh; 08-04-2008 at 06:49 PM..
uttaresh is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 08-05-2008, 10:42 AM Re: JavaScript Errors in Firefox and Safari
wayfarer07's Avatar
Poo on You

Latest Blog Post:
Introducing WowWindow
Posts: 3,985
Name: Abel Mohler
Location: Asheville, North Carolina USA
Trades: 0
Button1.value is invalid JavaScript, but it is a proprietary Microsoft method, so Opera imitates it, because it has a tendency to do so when it comes to JavaScript.

The correct way to set the value of #Button1 is like this:
HTML Code:
<script>
document.getElementById("Button1").value = "Clicked!";
</script>
This will work in all browsers.

You may think the Microsoft way is better, because it is shorter, but it is very very bad. Let me explain why. If I define a new object named Button1, it will conflict with your code the way it is written. If you ever introduce any code that has an object named button1, it will potentially override the Microsoft method.

Here is an example:
HTML Code:
Button1 = {
//properties and methods go here.
}
Bye bye Microsoft method.
__________________
Join me on
Please login or register to view this content. Registration is FREE
wayfarer07 is offline
Reply With Quote
View Public Profile Visit wayfarer07's homepage!
 
Old 08-05-2008, 05:23 PM Re: JavaScript Errors in Firefox and Safari
Novice Talker

Posts: 8
Trades: 0
Wow, it worked! Thanks a million, man!!

Guess Microsoft likes screwing with everyone who doesn't use their redundant products... nothing new.
uttaresh is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to JavaScript Errors in Firefox and Safari
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.27603 seconds with 12 queries