f



Javascript problem.

Try out the code below in an HTML file please. The problem is with the
javascript. I can't get the body to change. The code below is PHP
generated. Firefox says the problem is show() does not exist AFTER I
click on the link display[ link displayed says: test ]

<html>
<script>

function show( s ){

	document.write("<table><tr><td>"+ body( s ) +"</td></tr></table>");
return 0;
}

function body( s ){

	t = ' ';

	if ( s == "home" ){

		t += "hi home<BR><BR>";t += "<a href=\"\" onclick=\"show('test');
\">test</a>";
	}

	if ( s == "test" ){

		t += "this is test<BR><BR>";t += "<a href=\"\" onclick=\"show('home')
\">home</a>";
	}

	return t;
};

</script>

<body onload="show('home');">
<!--<script>show("home");</script>-->
</body>
</html>

Thank you.

0
6/21/2007 11:59:18 PM
comp.programming 11491 articles. 2 followers. Post Follow

3 Replies
868 Views

Similar Articles

[PageSpeed] 41

Merlyn[v7.0] wrote:

> Try out the code below in an HTML file please. The problem is with the
> javascript. I can't get the body to change. The code below is PHP
> generated. Firefox says the problem is show() does not exist AFTER I
> click on the link display[ link displayed says: test ]

Install a JavaScript library such as Prototype.js, and then use 
Element.update() or similar to replace a table body.

If problems persist, post to news:comp.lang.javascript

-- 
  Phlip
  http://flea.sourceforge.net/PiglegToo_1.html 


0
Phlip
6/22/2007 12:58:59 AM
On Jun 21, 8:58 pm, "Phlip" <phlip...@yahoo.com> wrote:
> Merlyn[v7.0] wrote:
> > Try out the code below in an HTML file please. The problem is with the
> > javascript. I can't get the body to change. The code below is PHP
> > generated. Firefox says the problem is show() does not exist AFTER I
> > click on the link display[ link displayed says: test ]
>
> Install a JavaScript library such as Prototype.js, and then use
> Element.update() or similar to replace a table body.
>
> If problems persist, post to news:comp.lang.javascript
>
> --
>   Phlip
>  http://flea.sourceforge.net/PiglegToo_1.html

Try replacing the href on your links with a # instead of leaving them
empty i.e. <a href="#"...

0
ajrisi
6/22/2007 3:48:41 AM
Hello, thank you for your tips. I started looking more into it and
found out about document.getElementById() and such, very useful,
here's the code that actually does what it's supposed to do:


<html>
	<script>

    var page = "<div id='X'></div>";

    function show( s ){

        w = document.getElementById("X");
        w.innerHTML = "<table><tr><td>"+ body( s ) +"</td></tr></
table>";
    }

    function body( s ){

        t = ' ';

        if ( s == "home" ){

            t += "hi home<BR><BR>";
            t += "<a href=\"javascript:show('test');\">test</a>";
        }

        if ( s == "test" ){

            t += "this is test<BR><BR>";
            t += "<a href=\"javascript:show('home')\">home</a>";
        }

        return t;
    }

    </script>
<body onload="show('home');">
	<script>
        document.write( page );
    </script>
</body>
</html>

0
Merlyn
7/9/2007 6:07:42 PM
Reply: