Click to See Complete Forum and Search --> : how to display as white spaces in javascript
raghu
04-03-2003, 11:18 AM
HI,
I have html page which contains two arrarys which basically
contains parent child relationship.
Finally from the array, I need to display like this
FATHER
SON
DAUGHTER.
and I CANNOT DO document.write since the position of the select box is not known and also it should work in netscape
and IE.
thanks in advance
hERE IS THE SAMPLE CODE.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title></title>
<meta name="GENERATOR" content="Microsoft Visual Studio.NET 7.0">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
</head>
<body>
<form id="f1" name="f1">
<select name="S1" id="S1" alt="Select a library context" >
</select>
</form>
<script>
var aBaseLib= new Array("FATHER,FATHER")
var aSubLib=new Array("FATHER"," SON,SON"," DAUGHTER,DAUGHTER")
var sLoadBaseLib =document.f1.S1;
for(var iBaseLib = 0;iBaseLib < aBaseLib.length; iBaseLib++)
{
var sBaseName = aBaseLib[iBaseLib].split(",");
sLoadBaseLib[sLoadBaseLib.length] = new Option(sBaseName[0],sBaseName[1]);
if(aSubLib != "" && sBaseName[0] == aSubLib[0])
{
for(var iSubLib = 1;iSubLib < aSubLib.length; iSubLib++)
{
var sSubName = aSubLib[iSubLib].split(",");
sLoadBaseLib[sLoadBaseLib.length] = new Option(sSubName[0],sSubName[1]);
}
}
}
</script>
</body>
</html>
gil davis
04-03-2003, 12:23 PM
This didn't make any sense the FIRST time you posted it. What spaces are you talking about?
If you want to post a link to your page, it would be better. Either that, or surround your code with [CODE] tags so that the forum won't mess up your post.
raghu
04-03-2003, 12:26 PM
Here is the code.
[code]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title></title>
<meta name="GENERATOR" content="Microsoft Visual Studio.NET 7.0">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
</head>
<body>
<form id="f1" name="f1">
<select name="S1" id="S1" alt="Select a library context" >
</select>
</form>
<script>
var aBaseLib= new Array("FATHER,FATHER")
var aSubLib=new Array("FATHER"," SON,SON"," DAUGHTER,DAUGHTER")
var sLoadBaseLib =document.f1.S1;
for(var iBaseLib = 0;iBaseLib < aBaseLib.length; iBaseLib++)
{
var sBaseName = aBaseLib[iBaseLib].split(",");
sLoadBaseLib[sLoadBaseLib.length] = new Option(sBaseName[0],sBaseName[1]);
if(aSubLib != "" && sBaseName[0] == aSubLib[0])
{
for(var iSubLib = 1;iSubLib < aSubLib.length; iSubLib++)
{
var sSubName = aSubLib[iSubLib].split(",");
sLoadBaseLib[sLoadBaseLib.length] = new Option(sSubName[0],sSubName[1]);
}
}
}
</script>
</body>
</html>
[code]
Thanks in advance
gil davis
04-03-2003, 12:58 PM
Change that last red thing to [/code], and then (maybe) the forum will render your code as intended.
Oh, yeah - and proof-read the results to make sure it is exactly what you meant it to be.
raghu
04-03-2003, 01:07 PM
I AM NOT SURE about what u r talking.
Also i am worried more about the solution,
and IT looks like the code is rendered properly.
Hopefully you have a solution for the problem?
gil davis
04-03-2003, 01:24 PM
The forum renders &nbsp; as a space (" "). Therefore, anywhere in your post that you typed that disappears.
Please use &amp;nbsp; wherever it occurs in your code, because it doesn't get through.
raghu
04-03-2003, 01:27 PM
HI,
Sorry for the trouble.
I have html page which contains two arrarys which basically
contains parent child relationship.
Finally from the array, I need to display like this
FATHER
" " SON
" " DAUGHTER.
and I CANNOT DO document.write since the position of the select box is not known and also it should work in netscape
and IE.
thanks in advance
hERE IS THE SAMPLE CODE.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title></title>
<meta name="GENERATOR" content="Microsoft Visual Studio.NET 7.0">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
</head>
<body>
<form id="f1" name="f1">
<select name="S1" id="S1" alt="Select a library context" >
</select>
</form>
<script>
var aBaseLib= new Array("FATHER,FATHER")
var aSubLib=new Array("FATHER"," SON,SON"," DAUGHTER,DAUGHTER")
var sLoadBaseLib =document.f1.S1;
for(var iBaseLib = 0;iBaseLib < aBaseLib.length; iBaseLib++)
{
var sBaseName = aBaseLib[iBaseLib].split(",");
sLoadBaseLib[sLoadBaseLib.length] = new Option(sBaseName[0],sBaseName[1]);
if(aSubLib != "" && sBaseName[0] == aSubLib[0])
{
for(var iSubLib = 1;iSubLib < aSubLib.length; iSubLib++)
{
var sSubName = aSubLib[iSubLib].split(",");
sLoadBaseLib[sLoadBaseLib.length] = new Option(sSubName[0],sSubName[1]);
}
}
}
</script>
</body>
</html>
gil davis
04-03-2003, 01:39 PM
I'm sorry, but I still think that something is missing from your post. When I put your code into my browser, it creates a drop-down box that looks like this:FATHER
SON
DAUGHTERIs that what it's supposed to do, or not?
Please do not just post your code yet another time, because you have already done that three times in this thread, with no apparent changes.
Change the extension on your actual HTML file to TXT and attach it to your next post, using the "Attach file" option.
raghu
04-03-2003, 01:52 PM
Hi,
My problem is that is displayed as
SON and DAUGTHER
It is not displaying as you said, it is displaying as
FATHER
SON
 DAUGTHER
in the dropdown box and this should work in both IE and Netscape.
I have renamed to a txt file.
gil davis
04-03-2003, 02:23 PM
This file gets rid of the &nbsp;, but it does not work in Netscape unless you refresh the page after it loads. There seems to be a bug in NS when it comes to dynamic drop-down boxes. Perhaps someone else knows a work-around.
raghu
04-03-2003, 02:27 PM
Gil,
Actually i knew the solution you have sent.But it
does not work in netscape.Since Netscape truncates all
the spaces.I want it to work in both netscape and IE.
I am sure there is some solution for this.
Thanks in advance