0

I have a textbox which is dynamically being added as

<div id="main"></div>


$(document).ready(function(){
    var time = '2014-04-20 00:00:00';
    var textbox = = '<input type="text" id="timeStatus" value='+time+'>';
    $('#main').html(textbox);
});

However, the value after the space 00:00:00 is not displayed.

1 Answer 1

3

That's because your HTML code ends upp looking like this:

<input type="text" id="timeStatus" value=2014-04-20 00:00:00>

As you don't have any quotation marks around the value for the value attribute, only the part before the space will be used as the value, the rest will be a separate (invalid) attribute.

You should add quotation marks so that the HTML code ends up like this:

<input type="text" id="timeStatus" value="2014-04-20 00:00:00">

That would be:

var textbox = '<input type="text" id="timeStatus" value="'+time+'">';
Sign up to request clarification or add additional context in comments.

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.