silvster27
silvster27

Reputation: 1936

jquery can't get the value from an input element

I am using jquery trying to retrieve the value of a text input but it is not working. can anyone see what I am doing wrong? http://jsfiddle.net/silvajeff/rJNLr/

<input id="mytest2" value="123"/>
<button id="findRow">Find Row</button>

$("#findRow").click(function() {   
  var theVal = $("#myTest2").val();
  alert(theVal);
});

I apologize to everyone, but what I initially posted was just a typo when I was breaking the question down to simplify it. I will have to repost again, only this time I'll put the unsimplified code here. I'll leave this question here though and add a tag for case-sensitive because I still think these were valuable solutions to others who may potentially have issues.

Upvotes: 0

Views: 3908

Answers (4)

Ahmed Assaf
Ahmed Assaf

Reputation: 601

Change id="mytest2" to id="myTest2"

Try this :

<input id="myTest2" value="123"/>
<button id="findRow">Find Row</button>

$("#findRow").click(function() {   
  var theVal = $("#myTest2").val();
  alert(theVal);
});

Which mean the id is case sensitiveness.

Upvotes: 2

TheWhiteRabbit
TheWhiteRabbit

Reputation: 15768

you have incorrectly mentioned the 'id' value of your field.

id values are CASE SENSITIVE in jQuery

hence, change

myTest2 to mytest2

Upvotes: 6

Adil
Adil

Reputation: 148160

You have used wrong id myTest2 which is not present use mytest2. Javascript is case sensitive so you need to take care.

Live Demo

$("#findRow").click(function() {   
  var theVal = $("#mytest2").val();
  alert(theVal);
});

Upvotes: 6

Arvind Bhardwaj
Arvind Bhardwaj

Reputation: 5301

Change $("#myTest2") to $("#mytest2")

Upvotes: 6

Related Questions