user7441072
user7441072

Reputation: 279

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

$('#add_input').click(function(){
var item = $('input[id="itemname"]').val();
i++;
 $('#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.

Upvotes: 0

Views: 214

Answers (2)

dodov
dodov

Reputation: 5844

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

You have:

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

When concatenated, it becomes:

value=hello

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

value="hello"

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.

Upvotes: 2

Lajos Arpad
Lajos Arpad

Reputation: 76434

The problem is here

value='+item+'

In your case ' was used to denote where your string starts and where it ends. " was used to denote where the HTML value starts and where it ends. The code was only specifying that item comes into the string dynamically, but it did not specify that it is an HTML value, thus the solution is

value="'+item+'"

Upvotes: 1

Related Questions