coderatlarge
coderatlarge

Reputation: 649

Unable to set value of input field

I have two input fields in my form:

<input type="hidden" id="search_category_id" name="cid" value="" /> 
<input type="hidden" id="search_category_name" name="cname" value="" />  

I want to set the value of these fields using jquery and here is how I am doing that:

jq("#search_category_id").value(id);
jq("#search_category_name").value(name);

id and 'name' both are getting valid values... I checked that using alert.

I am getting the following error:

TypeError: jq(...).value is not a function

What am I doing wrong?

Upvotes: 0

Views: 2205

Answers (1)

Zakaria Acharki
Zakaria Acharki

Reputation: 67505

The .value() is not a jQuery function you could use it with javascript object like :

document.getElementById("search_category_id").value(id);
document.getElementById("search_category_name").value(name);

But if you want to use jQuery Object you should use .val():

jq("#search_category_id").val(id);
jq("#search_category_name").val(name);

Hope this helps.

Upvotes: 1

Related Questions