The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Web Design
> JavaScript Development
|
Can anyone tell what's the difference between these code, please?
Discuss Can anyone tell what's the difference between these code, please? in the JavaScript Development forum on Dev Shed. Can anyone tell what's the difference between these code, please? JavaScript Development forum discussing JavaScript and DHTML, AJAX, and issues such as coding cross-browser JavaScript.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

February 18th, 2013, 11:55 PM
|
|
Contributing User
|
|
Join Date: Oct 2012
Posts: 53
Time spent in forums: 10 h 3 m 27 sec
Reputation Power: 1
|
|
|
Can anyone tell what's the difference between these code, please?
I got these two code that were supposed to be identical to each other.
But one works fine but the other one doesn't and I don't know why..
I used "http://www.diffnow.com/" for comparison.
And it tells me number of differences are 0 between them.
Also, the looks identical to each other( I even looked through them for a couple of times).
However, I'm not actually confident that these two are exactly the same as each other since only one works fine while the other one doesn't as I said. I might have used the site in a wrong way and misunderstood what it said as a result.
Anyways, codes are these two.
First one (one that works fine):
Code:
<!DOCTYPE html>
<html>
<body>
<script>
function showCertainCategory(selection)
{
var ulTag = document.getElementsByTagName('ul');
for(var i=0; i<ulTag.length; i++)
{
ulTag[i].style.display = "none";
if(ulTag[i].className == selection)
{
ulTag[i].style.display = "block";
}
else
{
ulTag[i].style.display = "none";
}
}
}
</script>
<form>
<select id="category" onChange="showCertainCategory(this.value)">
<option value="handle">handle</option>
<option value="wheel">wheel</option>
</select>
</form>
<ul class='handle'>
<li>Handle product A</li>
<li>handle</li>
</ul>
<ul class='wheel'>
<li>Wheel product B</li>
<li>wheel</li>
</ul>
<ul class='handle'>
<li>Handle product A2</li>
<li>handle</li>
</ul>
<ul class='wheel'>
<li>Wheel product B2</li>
<li>wheel</li>
</ul>
</body>
</html>
================================================
Second one(One that doesn't work)
Code:
<!DOCTYPE html>
<html>
<body>
<script>
function showCertainCategory(selection)
{
var ulTag = document.getElementsByTagName('ul');
for(var i=0; i<ulTag.length; i++)
{
ulTag[i].style.display = "none";
if(ulTag[i].className == selection)
{
ulTag[i].style.display = "block";
}
else
{
ulTag[i].style.display = "none";
}
}
}
</script>
<form>
<select id="category" onChange="showCertainCategory(this.value)">
<option value="handle">handle</option>
<option value="wheel">wheel</option>
</select>
</form>
<ul class='handle'>
<li>Handle product A</li>
<li>handle</li>
</ul>
<ul class='wheel'>
<li>Wheel product B</li>
<li>wheel</li>
</ul>
<ul class='handle'>
<li>Handle product A2</li>
<li>handle</li>
</ul>
<ul class='wheel'>
<li>Wheel product B2</li>
<li>wheel</li>
</ul>
</body>
</html>
|

February 19th, 2013, 12:40 AM
|
 |
Still alive
|
|
Join Date: Mar 2007
Location: Washington, USA
|
|
|
There are some unusual characters after the "var ulTag" line. Check the attachment.
Simply delete the line.
|

February 20th, 2013, 12:52 PM
|
|
Contributing User
|
|
Join Date: Oct 2012
Posts: 53
Time spent in forums: 10 h 3 m 27 sec
Reputation Power: 1
|
|
Thank you very much.
But how did you tell it?
and is having extra spaces between the lines so bad and why??
Quote: | Originally Posted by requinix There are some unusual characters after the "var ulTag" line. Check the attachment.
Simply delete the line. |
|

February 20th, 2013, 01:15 PM
|
 |
Still alive
|
|
Join Date: Mar 2007
Location: Washington, USA
|
|
|
I copy/pasted your code into Notepad so I could compare the two more easily. Notepad tends to show those squares for unusual/non-printable characters so they were hard to miss. So it was lucky, really.
It's not that the extra space is bad, it's what's present on that line. Deleting it makes the problematic characters go away; if you want the blank line then go ahead and add another one in.
|

February 21st, 2013, 04:56 AM
|
|
Contributing User
|
|
Join Date: Oct 2012
Posts: 53
Time spent in forums: 10 h 3 m 27 sec
Reputation Power: 1
|
|
Well I used Notepad that comes with Windows and I couldn't see any of those problematic characters..
Did you set it to certain mode or something??
Quote: | Originally Posted by requinix I copy/pasted your code into Notepad so I could compare the two more easily. Notepad tends to show those squares for unusual/non-printable characters so they were hard to miss. So it was lucky, really.
It's not that the extra space is bad, it's what's present on that line. Deleting it makes the problematic characters go away; if you want the blank line then go ahead and add another one in. |
|

February 21st, 2013, 12:05 PM
|
 |
Contributing User
|
|
|
|
The unusual characters requinix is referring to; and I am not sure how your missing it is:
In NotePad
They are right below the "ulTag" variable declaration. On this forum; they are represented as Ruby characters, but if you paste them into Notepad... they will look like small hollow squares. Delete these characters and the code will work fine. You can still keep the carriage return (to create a carriage return; all you have to do is press the "Enter" key, on your keyboard); just remove the characters.
|

February 26th, 2013, 01:15 AM
|
|
|
|
Some fonts will display nothing even in notepad for certain characters. Terminal is one of them. If you switch your font to Terminal in notepad you will quickly see how they could not see them.
|

February 27th, 2013, 03:52 AM
|
|
Contributing User
|
|
Join Date: Oct 2012
Posts: 53
Time spent in forums: 10 h 3 m 27 sec
Reputation Power: 1
|
|
|
well, I tried that font and other fonts too but it didn't work out that way.
I will just highlight everything so that I will find highlighted part that doesn't have any characters where it should be unusual characters.
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|