Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set value of textbox using JQuery

My Jade template -

input#main_search.span2(
    style = 'height: 26px; width: 800px;' ,
    type = 'text',
    readonly='true',
    name='searchBar',
    value='test'
)

JS file -

$('#searchBar').val('hi')
console.log('sup')

Console output -

sup

But searchBar value stats at test. What am I doing wrong?

like image 791
Narabhut Avatar asked Jul 09 '13 20:07

Narabhut


People also ask

How can add value in textbox using jQuery?

You can simply use the jQuery val() method to set the value of an input text box.


1 Answers

You are logging sup directly which is a string

console.log('sup')

Also you are using the wrong id

The template says #main_search but you are using #searchBar

I suppose you are trying this out

$(function() {
   var sup = $('#main_search').val('hi')
   console.log(sup);  // sup is a variable here
});
like image 195
Sushanth -- Avatar answered Oct 20 '22 02:10

Sushanth --