473,668 Members | 2,755 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

&nbsp not being read by Safari and Opera in JS

hsriat
1,654 Recognized Expert Top Contributor
I have to toggle the name of a hyperlink from Edit to Save and vice-versa on click event of the same hyperlink.

This is the HTML part,

[HTML]<input class="text" id="ix1" type=text></input>
<a class="button" id="ax1" href="javascrip t:void(0)" onclick="edit(' x1')">&nbsp;Edi t&nbsp;</a>[/HTML]



and function edit(id) is
Expand|Select|Wrap|Line Numbers
  1.       function edit(id) {
  2.       var anc = document.getElementById('a'+id);
  3.       var inp = document.getElementById('i'+id);
  4.       anc.innerHTML = anc.innerHTML=="&nbsp;Edit&nbsp;" ? "&nbsp;Save&nbsp;" : "&nbsp;Edit&nbsp;";
  5.       inp.className = inp.className=="text" ? "edit" : "text";
  6. }
The code in bottom line is working fine with all browsers, ie. class name of the input box gets changed on hyperlink's click.
But the name-change of the hyperlink is working fine with Firefox and IE only, ie, the name of the hyperlink gets changed from ' Save ' to ' Edit ' and ' Edit ' to ' Save ' on every click. But Opera and Safari are not doing any change.
If I remove the &nbsp;, then its working fine with all.
But since its a button kind of look, so I need to give space on both sides of the name.

I know I can solve it with this change...
Expand|Select|Wrap|Line Numbers
  1. anc.innerHTML = inp.className=="text" ? "&nbsp;Save&nbsp;" : "&nbsp;Edit&nbsp;";
but what's the problem with reading &nbsp;?
Feb 16 '08 #1
9 5750
acoder
16,027 Recognized Expert Moderator MVP
Do spaces work in place of &nbsp;?
Feb 16 '08 #2
hsriat
1,654 Recognized Expert Top Contributor
Do spaces work in place of &nbsp;?
Toggle thing is working fine, but spaces are not being shown. Thats why I used &nbsp;
Feb 16 '08 #3
acoder
16,027 Recognized Expert Moderator MVP
The unicode replacement, \u00a0, should work.
Feb 16 '08 #4
hsriat
1,654 Recognized Expert Top Contributor
The unicode replacement, \u00a0, should work.
Doesn't work with Opera and Safari.

Well don't worry about that, I solved it with other way out.

Thanks for trying. :)
Feb 16 '08 #5
acoder
16,027 Recognized Expert Moderator MVP
It should do. Does this not work?
Expand|Select|Wrap|Line Numbers
  1. anc.innerHTML = anc.innerHTML=="\u00a0Edit\u00a0" ? "&nbsp;Save&nbsp;" : "&nbsp;Edit&nbsp;";
What did you use in the end? I assume it must involve matching "Edit" instead of comparing the string.
Feb 16 '08 #6
hsriat
1,654 Recognized Expert Top Contributor
It should do. Does this not work?
Expand|Select|Wrap|Line Numbers
  1. anc.innerHTML = anc.innerHTML=="\u00a0Edit\u00a0" ? "&nbsp;Save&nbsp;" : "&nbsp;Edit&nbsp;";
What did you use in the end? I assume it must involve matching "Edit" instead of comparing the string.

Ok, I guess there is some difference the way browsers interpret &nbsp;

Coz'
Expand|Select|Wrap|Line Numbers
  1. anc.innerHTML = anc.innerHTML=="\u00a0Edit\u00a0" ? "&nbsp;Save&nbsp;" : "&nbsp;Edit&nbsp;";
works with Opera and Safari and not Mozilla and IE, while
Expand|Select|Wrap|Line Numbers
  1. anc.innerHTML = anc.innerHTML=="&nbsp;Edit&nbsp;" ? "&nbsp;Save&nbsp;" : "&nbsp;Edit&nbsp;";
works fine with Mozilla and IE and not Opera and Safari.

PS: Earlier, in last post, I said it doesn't work with Safari and Opera. That time I was trying
Expand|Select|Wrap|Line Numbers
  1. anc.innerHTML = anc.innerHTML=="\u00a0Edit\u00a0" ? "\u00a0Save\u00a0" : "\u00a0Edit\u00a0"
Feb 16 '08 #7
acoder
16,027 Recognized Expert Moderator MVP
I think your best bet would be something like:
Expand|Select|Wrap|Line Numbers
  1. anc.innerHTML = anc.innerHTML.match("Edit") ? "&nbsp;Save&nbsp;" : "&nbsp;Edit&nbsp;";
Feb 16 '08 #8
hsriat
1,654 Recognized Expert Top Contributor
I think your best bet would be something like:
Expand|Select|Wrap|Line Numbers
  1. anc.innerHTML = anc.innerHTML.match("Edit") ? "&nbsp;Save&nbsp;" : "&nbsp;Edit&nbsp;";
Yeh, that works!

Thanks :)
Feb 16 '08 #9
acoder
16,027 Recognized Expert Moderator MVP
No problem, you're welcome!
Feb 16 '08 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

12
6026
by: Tjerk Wolterink | last post by:
In XHTML the entity nbsp stands for   A normal space like " " is also displayed as an normal space, but multiple spaces like " " are interpreted as 1 space in the xhtml page. So there comes the &nbsp; in handy: with "&nbsp;&nbsp;" you have two spaces. So with the nbsp entity you can create multiple spaces (in the display). Now i have an xml file with &nbsp; entities, i put it in an xsl-file that know xhtml entities.
13
6347
by: rbronson1976 | last post by:
Hi all, I have a very simple page that Firefox has problems with: www.absolutejava.com/testing.htm First of all, this page seems to be perfectly valid XHTML Strict. Both the W3C validator as well as Page Valet indicate it is valid. The page is being served with the proper MIME type of "application/xhtml+xml". Unfortunately, Firefox will not display the page due to a non-breaking
12
47692
by: Robert Mark Bram | last post by:
Hi All, I am using the following trim function: function trim (str) { return str.replace(/^\s*/g, '').replace(/\s*$/g, ''); } The problem is that this doesn't trim instances of the "&nbsp;" char - the non breaking space. Can this be represented in a grep statement at
2
1979
by: Rob T | last post by:
I have a dropdown list that I would like to put in a bunch of &nbsp;'s into it (I'm setting the font to a monospace font so I can show a couple of columns nice and neat). In the old asp days, I had no problem doing this, but now if I try to do something like this... boxOption.Items.Add(New ListItem("myFirstCol&nbsp;&nbsp;&nbsp;myLastCol")) ....it converts each & to a &amp;
9
5817
by: Jouni Karppinen | last post by:
I create a HTMLTable in my C# code and then add rows and cells into that table. I'm trying to set top and bottom border for each cell by using stylesheet and it works as far as cell has some text in it. If cell has no content at all, the borders do not show up (..strange) So I tried to insert text inside each cell which has no other content inside. Cell content is set in code:
3
8916
by: yawnmoth | last post by:
<? echo 'a'.trim(html_entity_decode('&nbsp;a&nbsp;')).'a'; ?> Shouldn't PHP output aaa? Looking at the documentation for trim I see that it doesn't support chr(0xA0) (eg. html_entity_decode('&nbsp;')), but it seems to me like it ought to...
28
13185
by: entfred | last post by:
I have the following line of html: &nbsp;&nbsp1234&nbsp;&nbsp;&nbsp;&nbsp;&nbspabc&nbsp;&nbsp;&nbspyow In Internet Explorer 6.0, the columns look ok using the above html: 1234 abcd yow But, in firefox, for same html, getting this:
4
17873
by: ckirchho | last post by:
Hallo, In a form I have several text or checkbox inputs with their appropriate labels. I'd like to keep label and input together, so I connect them with a &nbsp;, like: <input type="checkbox" name="h" value="1" id="chk"/>&nbsp;<label for="chk">Schreibweisentolerant</label> Apparently this doesn't work in Firefox 2. It works in IExplorer and Opera. As well I tried:
7
9745
by: Sebarry | last post by:
Hi, I'm having trouble creating a blank table row in Javascript using document.createElement( '&nbsp;' ). When I look at the generated source it has intrepreted it as <td>&amp;nbsp;</td>. What do I need to do? I've tried using single quotes, double quotes and backslash. Thanks, Sean
0
8462
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8797
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8583
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7401
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6209
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5681
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4205
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2023
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1786
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.