Solved

get text from inpu

Posted on 2014-11-20
9
59 Views
Last Modified: 2014-12-08
Hi,

I am trying to get the text from an input of type text like so:
<input type="text" id="inpAvg" name="gasaverage" value="" style="width: 60%;" />

Open in new window

with this jQuery
var avg = $("#inpAvg").val();

Open in new window

but it returns an empty string no matter what I put in the input.

What is wrong?

Best regards
RTSol
0
Comment
Question by:RTSol
  • 4
  • 2
  • 2
  • +1
9 Comments
 
LVL 82

Expert Comment

by:leakim971
ID: 40455329
http://jsfiddle.net/zrej6aj8/

<input type="text" id="inpAvg" name="gasaverage" value="IM NOT EMPTY" style="width: 60%;" />
0
 
LVL 2

Expert Comment

by:Elxn
ID: 40455361
You should remove the value="" part of the input HTML.
0
 

Author Comment

by:RTSol
ID: 40455510
It's very dtrange but nothing of the above works fro me. The input resides inside a view in a hybrid mobile app. I am going nuts. Any ideas?
0
 
LVL 2

Accepted Solution

by:
Elxn earned 250 total points
ID: 40455522
Are you sure you don't have another element with the same ID?  Sounds like you have quite a bit of code.
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

Author Comment

by:RTSol
ID: 40455558
It's a lot of code but the id is unique
0
 
LVL 82

Expert Comment

by:leakim971
ID: 40455723
provide a link this website
0
 

Author Comment

by:RTSol
ID: 40455846
Well - it is a mobile app so I can't.
0
 
LVL 10

Assisted Solution

by:Hans Langer
Hans Langer earned 250 total points
ID: 40463094
obviously you are getting a different element.
- try using a different ID,
- try getting it by the name $("[name='gasaverage']").val()
- be sure that the "val()" and "$" function are not overwritted. Use document.getElementId('inpAvg').value
- are you using iframes? or frames?
0
 

Author Closing Comment

by:RTSol
ID: 40486499
Hi guys,

Sorry for the delay. It actually was a problem with multiple IDs. I was using requirejs and didn't realize that all the html was lodaed when the app was run. stupid of me - thanks.

Best regards
RTSol
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
In this Micro Tutorial viewers will learn how to create navigation buttons that change on rollover, using CSS (Continuation of the CSS Image Sprite tutorial) Create a parent ID for all the list items       - Specify position: absolute and display: block…
The viewer will learn how to dynamically set the form action using jQuery.

930 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now