views:

91

answers:

2
+1  Q: 

InnerHTML issue

How do I get the values of textboxe's along with innerHTML?

For example, if I have

<html>
   <head>
   </head>
        <body>
            <div id="getvalue">
          <p><input type="text" name="username" id="username"></p>
     </div>

       </body>
</html>

I need the innerHTML of the particlular id="getvalue" along with the textbox value. I got the result if i use

var gotvalue=document.getElementBYId('getvalue').innerHTML;

I just got the result

"<p><input type="text" name="username" id="username"></p>"

Also, I need the textbox value along with the innerHTML. How could i do this?

Thanks in advance.

+5  A: 

You want the .value property of the <input> element, like this:

var gotvalue = document.getElementById('getvalue').innerHTML;
var inpitvalue = document.getElementById('username').value;
Nick Craver
+2  A: 

As i can only imagine one halfway good reason for what you need the innerHTML(put it somewhere else into the document for copying), I would suggest to use the DOM-method to get the copy: cloneNode(true) and also use a DOM-Method(which one depends on where to put) to inject it into the DOM.
cloneNode() will preserve the attributes too, so the value will also be copied.
If you really need the string, forget this ^^

Dr.Molle