MDanz Posted February 21, 2010 Share Posted February 21, 2010 what i'm trying to do is get the contents of the textarea, which the id is 'reply'. then onclick of a button, a popup div with id 'layer1' displays the contents of the textarea. i tried below but it comes up blank. i haven't included the pop up/button code, thats working. <textarea name="reply" id="reply">testing</textarea> <div id="layer1"></div> var newtext2 = document.getElementById('reply').value; document.getElementById('layer1').innerhtml = newtext2; so onclick of the button it should display "testing" in the div. Quote Link to comment Share on other sites More sharing options...
Psycho Posted February 21, 2010 Share Posted February 21, 2010 JavaScript is picky about the case of the functions/properties. You should be using innerHTML Quote Link to comment Share on other sites More sharing options...
MDanz Posted February 21, 2010 Author Share Posted February 21, 2010 here is the full code. I just want the contents of the textarea to appear in the pop up div. this isn't working though. <html> <head> <style type="text/css"> #layer1 { position: absolute; visibility: hidden; width: 300px; height: 300px; margin-left: 50%; margin-right: 50%; background-color: #000000; border: 1px solid #FBB917; padding: 10px; } #close { float: right; font-family:Arial, Helvetica, sans-serif; }</style> <title>Live Help</title> <script type="text/javascript"> <!-- x = 20; y = 70; function setVisible(obj) { obj = document.getElementById(obj); obj.style.visibility = (obj.style.visibility == 'visible') ? 'hidden' : 'visible'; var obj = ( function( thisId ) { var myObj = document.getElementById( thisId ) || document.all[ thisId ]; return myObj; } ); var newtext2 = obj( "reply" ).value; obj( "layer1" ).innerHTML = (( newtext2 ) ? newtext2 : "null" ); } function placeIt(obj) { obj = document.getElementById(obj); if (document.documentElement) { theLeft = document.documentElement.scrollLeft; theTop = document.documentElement.scrollTop; } else if (document.body) { theLeft = document.body.scrollLeft; theTop = document.body.scrollTop; } theLeft += x; theTop += y; obj.style.left = theLeft + 'px' ; obj.style.top = theTop + 'px' ; setTimeout("placeIt('layer1')",500); } window.onscroll = setTimeout("placeIt('layer1')",500); --> </script> </head> <body> <div> <textarea name="reply" id="reply" naame="reply" rows="3" cols="30">testing</textarea> <input type="button" value="test" onclick="setVisible('layer1');return false' target='_self'" /> <div id="layer1"></div> </div> </body> </html> it works correctly like this without a popup div.. <html> <head> <title>Live Help</title> <script type="text/javascript"> <!-- var getVal = (function() { var obj = ( function( thisId ) { var myObj = document.getElementById( thisId ) || document.all[ thisId ]; return myObj; } ); var newtext2 = obj( "reply" ).value; obj( "layer1" ).innerHTML = (( newtext2 ) ? newtext2 : "null" ); }); --> </script> </head> <body> <form id="form1" method="post" action="#" onsubmit="return false;"> <div> <textarea name="reply" id="reply" naame="reply" rows="3" cols="30">testing</textarea> <input type="button" value="test" onclick="getVal();" /> <div id="layer1"></div> </div> </form> </body> </html> Quote Link to comment Share on other sites More sharing options...
Psycho Posted February 22, 2010 Share Posted February 22, 2010 First off you have a problem with matching your quote marks in the input tag: <input type="button" value="test" onclick="getVal(); setVisible('layer1');return false' target='_self'" /> You open the onclick with a double quote, but try and close with a single quote. There is also an extra double quote at the end of the target parameter. Second, "name" has only one "a", not two <textarea name="reply" id="reply" naame="reply" rows="3" That should fix most of your problems except one. This line window.onscroll = setTimeout("placeIt('layer1')",500); is failing with the error message "Not implemented". Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.