0

How can I get the input field from the innerHTML which is a string? getElementById does not work obviously.

div.innerHTML = "<input id=\"ValueField\" name=\"test1\" value=\"1\" type=\"hidden\">"
4
  • could you be more precise please? a jsFiddle would be useful Commented Mar 8, 2013 at 10:30
  • Clear your question. What you want ? input field or value ? Commented Mar 8, 2013 at 10:30
  • 1
    well your js above is invalid for a start. you have un-delimited "'s Commented Mar 8, 2013 at 10:32
  • @Liam the code is copied from the visual studio debugger... ;-) Commented Mar 10, 2013 at 16:50

2 Answers 2

2

Try the code below:

var div = document.getElementById('div');
div.innerHTML = '<input id="ValueField" name="test1" value="1" type="hidden" />';
var input = document.getElementById('ValueField'); 
Sign up to request clarification or add additional context in comments.

Comments

1

If you want to get it as a string this is the solution

div.innerHTML = '<input id="ValueField" name="test1" value="1" type="hidden">'

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.