user2826111
user2826111

Reputation: 152

issue to set text inside input field

I have search program where I have to find some text after click on that search result it should set into input box but it gives me some space before text

You can check it on below link:

http://jsfiddle.net/VcXtC/

$("tbody > tr").click(function(){
    var proid = $(this).text().split(":"); $("#searchInput").val(proid[0]);
});

Upvotes: 1

Views: 76

Answers (4)

Dhaval Bharadva
Dhaval Bharadva

Reputation: 3083

use jquery trim for this Reference API

Replace :

$("#searchInput").val(proid[0]);  

To:

$("#searchInput").val(proid[0].trim());  

You should trigger click event like

$("tbody > tr > td").click(function(){
    var proid = $(this).text().split(":"); $("#searchInput").val(proid[0].trim());
});

JSFIDDEL DEMO

Upvotes: 2

Change $("tbody > tr") to $("tbody td") to select the table cell instead of the row.

Upvotes: 1

Tats_innit
Tats_innit

Reputation: 34107

Working demo http://api.jquery.com/jQuery.trim/

API:

.trim: http://api.jquery.com/jQuery.trim/

code

$("tbody > tr").click(function(){
    var proid = $(this).text().split(":");
    alert(proid[0]);
    $("#searchInput").val(proid[0].trim());
});

Upvotes: 4

Barmar
Barmar

Reputation: 781004

That's because of all the spaces between <tr> and <td>. Either put the click handler on the tbody > tr > td, or use proid[0].trim() to remove the spaces.

FIDDLE

Upvotes: 2

Related Questions