Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Jun 2004
    Location
    Dallas
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    problem with SIMPLE .replaceChild function...

    I have a very simple function that attempts to use .replaceChild to replace a piece of text within a <p> element. It works fine with .appendChild, but fails with .replaceChild. The error is:

    Microsoft Jscript runtime error:
    Line: 9
    Char: 5
    Error: Argument not optional

    I am very new to Javascript, and am just trying to establish proof of concept for this to incorporate into a site that I am working on. I just ordered the JS Def. Guide this morning, but until then, if anyone can tell me in a textbooky sort of way - what my error is, and more importantly, why (what are required args. for this function, etc) - I would appreciate it +++

    TIA - scott

    My page is as follows - closing HTML tag removed because it was screwing up the forum CODE tags...

    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    	<head>
    		<script type="text/javascript">
    			<!-- hide
    				function changeText(){
    					var newText = document.createTextNode ("some new text here");
    					var para = document.getElementById("T1");
                           para.replaceChild(newText);
                           return false;
    				}
    			<!-- show -->
    		</script>
    		<title>jsTest</title>
    		<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    	</head>
    	<body>
    		<p id="T1">this is the text I want to change.</p>
    		<a href="#" onClick="changeText();">click me</a>
    	</body>
    ---------------------------

  • #2
    New Coder
    Join Date
    May 2004
    Posts
    51
    Thanks
    0
    Thanked 0 Times in 0 Posts
    when u trying replace the tag with a text .... no ? if u use appendChild u are adding the text in the tag....

  • #3
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    10,966
    Thanks
    0
    Thanked 236 Times in 233 Posts
    replaceChild expects two parameters: new child node and old child node.
    Try this:
    Code:
    function changeText(){
        var newText = document.createTextNode("some new text here");
        var para = document.getElementById("T1");
        para.replaceChild(newText, para.firstChild);
        return false;
    }
    ...
    <a href="#" onClick="return changeText();">click me</a>

  • #4
    New to the CF scene
    Join Date
    Jun 2004
    Location
    Dallas
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    That Was It - Thank You!

    I never put anything in all caps. But really thanks. You've made my day.

  • #5
    New to the CF scene
    Join Date
    Jun 2004
    Location
    Dallas
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Resolved...

    Hey. I could not find a link to mark this thread as "resolved". Am I missing something? New to this forum - I'm used to PHP builder...


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •