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 Coder
    Join Date
    Dec 2006
    Posts
    30
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Internet Explorer variables in innerHTML

    Hi,

    I am creating an ajaxscript and used some innerHTML to replace some contents. But now I would like to use some values from the updated content.

    How can I access these variables? I am using this code to update the innerHTML of a div with an inputfield and button. But now I would like to use the value of the input field in another function.

    I can't seem to find the correct way of accessing it through the DOM...

    Code:
    function editSite(siteId, siteNaam){
    	var x = document.getElementById(siteId);	
    	x.innerHTML = "<input type='text' value='" + siteNaam + "' onfocus='this.select(); this.style.backgroundColor=\"red\";' onblur='this.style.backgroundColor=\"white\";' />"
    				+ "<input id='save_button' type='submit' value='save' onclick='UpdateSite(\"" + siteNaam + "\");' />";
    }
    Does anyone have any ideas?

    Thanks

  • #2
    Senior Coder
    Join Date
    Mar 2005
    Location
    Portsmouth UK
    Posts
    4,505
    Thanks
    3
    Thanked 501 Times in 488 Posts
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
        "http://www.w3.org/TR/html4/loose.dtd">
    
    <html>
    
    <head>
      <title></title>
    <script language="JavaScript" type="text/javascript">
    <!--
    function editSite(siteId, siteNaam){
    	var x = document.getElementById(siteId);
    	x.innerHTML = "<input type='text' value='" + siteNaam + "' onfocus='this.select(); this.style.backgroundColor=\"red\";' onblur='this.style.backgroundColor=\"white\";' />"
    				+ "<input id='save_button' type='submit' value='save' onclick='UpdateSite(\"" + siteNaam + "\");' />";
    }
    
    //-->
    </script>
    </head>
    
    <body onload="editSite('siteId', 'siteNaam');">
    <div id="siteId" ></div>
    <input type="button" name="" value="Change Value" onclick="document.getElementById('siteId').getElementsByTagName('INPUT')[0].value='fred';">
    </body>
    
    </html>
    Vic

    God Loves You and will never love you less.

    http://www.vicsjavascripts.org/Home.htm

    If my post has been useful please donate to http://www.operationsmile.org.uk/

  • #3
    New Coder
    Join Date
    Dec 2006
    Posts
    30
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi Philip,

    I understand what you did, but I do not seem to be able to get it to work. Or I might just be doing it very wrong.

    This is what I did:

    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
        "http://www.w3.org/TR/html4/loose.dtd">
    <HTML>
    <HEAD>
    <TITLE></TITLE>
    <SCRIPT language="JavaScript" type="text/javascript">
    <!--
    function UpdateSite(siteNaam, waarde){
    	alert("sitenaam = " + siteNaam + "\n waarde = " + waarde);
    }
    
    
    function editSite(siteId, siteNaam){
    	var x = document.getElementById(siteId);
    	x.innerHTML = "<input type='text' value='" + siteNaam + "' onfocus='this.select(); this.style.backgroundColor=\"red\";' onblur='this.style.backgroundColor=\"white\";' />"
    				+ "<input id='save_button' type='submit' value='save' onclick='UpdateSite(\"" + siteNaam + "\", document.getElementById('siteId').getElementsByTagName('INPUT')[0].value;' />";
    }
    
    //-->
    </SCRIPT>
    </HEAD>
    <BODY onLoad="editSite('siteId', 'siteNaam');">
    <DIV id="siteId" ></DIV>
    </BODY>
    </HTML>
    I do not get an error. But also no result at all.

    Do you know what is wrong???

  • #4
    Senior Coder
    Join Date
    Mar 2005
    Location
    Portsmouth UK
    Posts
    4,505
    Thanks
    3
    Thanked 501 Times in 488 Posts
    well I got loads of errors
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
        "http://www.w3.org/TR/html4/loose.dtd">
    <HTML>
    <HEAD>
    <TITLE></TITLE>
    <SCRIPT language="JavaScript" type="text/javascript">
    <!--
    function UpdateSite(siteNaam, waarde){
    	alert("sitenaam = " + siteNaam + "\n waarde = " + waarde);
    }
    
    
    function editSite(siteId, siteNaam){
    	var x = document.getElementById(siteId);
    	x.innerHTML = "<input type=text value=" + siteNaam + " onfocus=\"this.select();this.style.backgroundColor='red'\"; onblur=\"this.style.backgroundColor='white';\" />";
    	x.innerHTML+= "<input id=\"save_button\" type=\"submit\" value=\"save\"  onclick=\"UpdateSite('" + siteNaam + "',document.getElementById('siteId').getElementsByTagName('INPUT')[0].value);\" />";
    }
    
    //-->
    </SCRIPT>
    </HEAD>
    <BODY onLoad="editSite('siteId', 'siteNaam');">
    <DIV id="siteId" ></DIV>
    </BODY>
    </HTML>
    Vic

    God Loves You and will never love you less.

    http://www.vicsjavascripts.org/Home.htm

    If my post has been useful please donate to http://www.operationsmile.org.uk/

  • #5
    New Coder
    Join Date
    Dec 2006
    Posts
    30
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks a million!!!


  •  

    Posting Permissions

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