JavaScript Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsWeb DesignJavaScript Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old December 2nd, 2012, 11:04 AM
mahesh_chavan mahesh_chavan is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 2 mahesh_chavan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 m 13 sec
Reputation Power: 0
How to make permanent changes using Javascript in Firefox

I am using javascript to change font/size and text ( innerhtml)
The changes made by javascript remain permanent in Internet Explorer, where as in Firefox ( I have tried ver. 7 to 16.0.2 ) changes are only momentary. If alert is used in the function, then the changes remain effective only till alert window is there.
The html is:
Code:
<HTML>
<BODY BGCOLOR#FFFF00>
<HEAD><TITLE>Showing Charset</TITLE>
<STYLE type="text/css">
.head_class {color:red;font-size:60;font-family:impact;}
</STYLE>
<script type="text/JavaScript">
function chngFont()
{
var el2 = document.getElementById('myfont');
var sfont = el2.value;
document.getElementById('head').className = 'head_class';
document.getElementById('head').innerHTML = sfont;
alert(document.seefont.fonttosee.value);
}

</script>
</head>
<body bgcolor=#ffff00>
<h1 align=center id="head">Charset</h1>
<form name=seefont >
<input type="text" id="myfont" name="fonttosee" size=20 value="arial">
<button onclick="chngFont()">Change font</button>
</form>
</BODY></HTML>

When I click the button class head_class is applied to heading id "head" and even the text is change to font name entered but just momentarily. If I use alert in the function, the changes remain only till alert is on the screen.
The same code works in IE forever ( The changes remain permanent.
What are the settings in firefox to make the changes using javascript permanent ?

Last edited by Kravvitz : December 3rd, 2012 at 06:55 PM. Reason: fixed the code tags

Reply With Quote
  #2  
Old December 3rd, 2012, 06:40 PM
web_loone08's Avatar
web_loone08 web_loone08 is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Aug 2008
Posts: 601 web_loone08 User rank is Second Lieutenant (5000 - 10000 Reputation Level)web_loone08 User rank is Second Lieutenant (5000 - 10000 Reputation Level)web_loone08 User rank is Second Lieutenant (5000 - 10000 Reputation Level)web_loone08 User rank is Second Lieutenant (5000 - 10000 Reputation Level)web_loone08 User rank is Second Lieutenant (5000 - 10000 Reputation Level)web_loone08 User rank is Second Lieutenant (5000 - 10000 Reputation Level)web_loone08 User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 1 Day 13 h 25 m 38 sec
Reputation Power: 69
Code:
HTML
<form name=seefont onsubmit="return false">


FireFox is assuming the button tag, in your form, is a submit button. At least; that's what I think it's doing. So you need to prevent a form submission, when the button is clicked.
Comments on this post
Kravvitz agrees!

Reply With Quote
  #3  
Old December 3rd, 2012, 06:59 PM
Kravvitz's Avatar
Kravvitz Kravvitz is offline
CSS & JS/DOM Adept
Dev Shed God 30th Plane (19500 - 19999 posts)
 
Join Date: Jul 2004
Location: USA
Posts: 19,831 Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level) 
Time spent in forums: 6 Months 1 Day 19 h 19 m 2 sec
Reputation Power: 4192
web_loone08 is correct.

To add to what web_loone08 said, this is a known bug in IE's "backwards compatibility mode" (aka "quirks mode"). The default type of the <button> element is "submit", not "button". The first thing to do is to add a doctype before the <html> start tag to tell IE to use "standards mode".
Code:
<!DOCTYPE html>
<HTML>
<HEAD>

Then an alternative to the solution web_loone08 suggested would be to add the type attribute to the <button>:
Code:
<button type="button" onclick="chngFont()">Change font</button>
__________________
Spreading knowledge, one newbie at a time. I'm available for hire at Dynamic Site Solutions.

Check out my blog. | Learn CSS. | PHP includes | X/HTML Validator | CSS validator | Common CSS Mistakes | Common JS Mistakes

Remember people spend most of their time on other people's sites (so don't violate web design conventions).

Last edited by Kravvitz : December 3rd, 2012 at 07:06 PM.

Reply With Quote
  #4  
Old December 3rd, 2012, 07:06 PM
BarryG BarryG is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2011
Location: Sydney Australia
Posts: 131 BarryG User rank is Second Lieutenant (5000 - 10000 Reputation Level)BarryG User rank is Second Lieutenant (5000 - 10000 Reputation Level)BarryG User rank is Second Lieutenant (5000 - 10000 Reputation Level)BarryG User rank is Second Lieutenant (5000 - 10000 Reputation Level)BarryG User rank is Second Lieutenant (5000 - 10000 Reputation Level)BarryG User rank is Second Lieutenant (5000 - 10000 Reputation Level)BarryG User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 3 Days 7 h 51 m 28 sec
Reputation Power: 83
Quote:
Originally Posted by mahesh_chavan
I am using javascript to change font/size and text ( innerhtml)
The changes made by javascript remain permanent in Internet Explorer, where as in Firefox ( I have tried ver. 7 to 16.0.2 ) changes are only momentary. If alert is used in the function, then the changes remain effective only till alert window is there.



You've got lots of html errors in there, like 2 <body> tags for a start, and unquoted attribute values.
But you form is being submitted, and the new page loads the original values.

So this code stops the "submit" from happening, but you are specifying the font in the .head_class style, so no matter what font name you type, you get "impact".
Code:
<HTML>
<HEAD><TITLE>Showing Charset</TITLE>
<STYLE type="text/css">
.head_class {
	color:red;
	font-size:60;
	font-family:impact; 
	}
</STYLE>
<script type="text/JavaScript">
function chngFont()
{
var el2 = document.getElementById('myfont');
var sfont = el2.value;
document.getElementById('head').className = 'head_class';
document.getElementById('head').innerHTML = sfont;
alert(document.seefont.fonttosee.value);
}

</script>
</head>
<body bgcolor="#ffff00">
<h1 align="center" id="head">Charset</h1>
<form name="seefont" action="#" onsubmit="return false">
<input type="text" id="myfont" name="fonttosee" size="20" value="arial">
<button onclick="chngFont()">Change font</button>
</form>
</BODY></HTML>


If you actually want to change the text to the font family you enter, insert this line right above your alert
Code:
document.getElementById('head').style.fontFamily = sfont;


That will over-ride the head_class font.

Last edited by BarryG : December 3rd, 2012 at 10:21 PM.

Reply With Quote
  #5  
Old December 4th, 2012, 05:44 AM
mahesh_chavan mahesh_chavan is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 2 mahesh_chavan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 m 13 sec
Reputation Power: 0
Yes, answer is correct

Thank you so much all who have helped.
Return false works great !

Reply With Quote
Reply

Viewing: Dev Shed ForumsWeb DesignJavaScript Development > How to make permanent changes using Javascript in Firefox

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap