user7441072 user7441072 -4 years ago 87
Javascript Question

not getting full value on textbox using jquery

i used .val() function in jquery to post value from textbox. when i alert i can see whole string .but when putting on a textbox only data before space is coming.anybody know this issue,please help
am sharing my code here

var item = $('input[id="itemname"]').val();
$('#dynamic1').append('<tr id="row'+i+'">\n\
<><td> <input type="text" name="serial_id" id="serial" value='+i+' ></td>\n\
<td><input type="text" name="item1[]" value='+item+'></td></tr>');

in item texbox only getting first part of input value.

Answer Source

Let's say item has the string hello in it.

You have:

'... value='+item+'...'

When concatenated, it becomes:


This is not proper HTML syntax. hello needs to be surrounded by quotes:


This means you need to change your code to:

'... value="'+item+'"...'
// --------^--------^----

In HTML5, quotes are optional for values that don't contain special characters or spaces. If they do, however, quotes are needed to identify where the value starts and ends. View this for more information.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download