Click here to Skip to main content
16,018,418 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Here is a simple html textbox in my form.

HTML
<input type="text" class="form-control InteractionText" id="InteractionFinalText" />


Now when I am accessing this textbox value in jQuery I am not getting the value entered in it by writing like this

HTML
$(".InteractionText").value

(OR)
$("#InteractionFinalText").value


interestingly it is working fine when I am accessing like this, it was so surprising for me why we should access by Index value, moreover why with second index.?

HTML
$(".InteractionText")[2].value


Note that i am sure in my page only one element with class "InteractionText", of course if I access with id also I am facing the same issue.?

Is I am missing any simple point in fundas of jQuery.? Or what causes this kind of scenario, any help will reduce my headache because of this simple issue I am wasting my time by browsing in net.
Posted

Hi Saikrishna,

If you are using jquery then try as shown below
JavaScript
$('#InteractionFinalText').val();

If you are using javascript then try this way
JavaScript
document.getElementById('InteractionFinalText').value;
 
Share this answer
 
v3
Comments
Saikrishna35 4-May-15 5:06am    
Thanks for the reply Libin, I can get the required thing in several ways, But why it was happening like this means why should I go with index even there is only one single class name available in my form.?
Libin C Jacob 28-May-15 3:31am    
Hi Saikrishna,
You can have multiple controls with the same class name. Once we take a control have a particular class name that will be an array of controls. As you know even if an array contains a single value, it can access only by an index. I think you get the point.
Hi Saikrishna,

It is possible for you to create jsfiddle demo.

thanks in advance.
 
Share this answer
 
Comments
Saikrishna35 7-May-15 2:34am    
Hi Rashmi, Thanks for the reply.
I was not able to create a sample page in jFiddle or no other place because I am using a big dynamic javascript code where the controls are created dynamically and adding to the solution. But still I am trying to produce it.
Thanks
hi,

it's ok if you are not able to make demo because of dynamic contents...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900