jquery mobile get value from input - jquery-mobile

I'm trying get the value from a input but it doesn't work
I have:
<input id="inputA" name="inputA" type="number" value="25" />
and:
var pot = $('#inputA').val();
Also, I have tried:
var pot = $('#inputA').text();
But it doesn't work.
I need help please!

Try to console $('#inputA') before you get its value, if it undefined, may be this document will help you http://jquerymobile.com/demos/1.2.1/docs/api/events.html

Related

How to get the value of a checkbox flipswitch in JQuery Mobile 1.4.5?

I'm using following markup to create a checkbox-based Flipswitch in jQuery Mobile 1.4.5:
<label for="flip-1">Checkbox Flip switch:</label>
<input data-role="flipswitch" name="flip-1" id="flip-1" type="checkbox">
Apparently, the same method to get the value for a select-based Flipswitch:
$("#flip-1").val()
is not working with the checkbox-based version, and i'm getting always the value of "on".
What i'm doing wrong here? Is there a way to get the value as for the select-based version?
Fiddle: http://jsfiddle.net/2ckHr/296/
Thanks in advance
Instead of reading .val() read the checked property:
alert($("#flip-1").prop("checked"));
Updated FIDDLE

Get Textarea Value with Simpe HTML Dom

i using simple_html_dom.php
how to get textarea value if the website has used bad tag.
the textarea tag already closed before </textarea> like input tag.
Textarea HTML like below:
<textarea name="xxx" id="xxx" />this is value</textarea>
When i use this function, i dont get anything
$textarea = $html->find("textarea[name=xxx]");
$contents = $textarea->innertext;
echo $contents;
how to get 'this is value' using simple_html_dom.php or other alternative?
Thank you
Well, my previous comment won't work in this case, I'll leave it for info though...
Another approach is to clean it up before parsing it with simple_html_dom using Tidy extension. But it seems not to be working here either...
A last approach I can think of, and if this is your only problematic case, is to use regex to get what you want:
Using <textarea.*?name="xxx".*?id="xxx".*?\/>([^<]+)<\/textarea> ==> RegEx DEMO
The output will be in group one of the resulting array $match. Check this working code:
$input = <<<_DATA_
<textarea name="xxx" id="xxx" />this is value</textarea>
_DATA_;
$pattern = '/<textarea.*?name="xxx".*?id="xxx".*?\/>([^<]+)<\/textarea>/';
preg_match($pattern, $input, $match);
var_dump($match)
Working DEMO
It is easy to get the value of a Teaxtarea in javascript:
<script type=text/javascript>
function getValueTextarea()
{
var vl=document.getElementById("tx").value;
alert(vl);
}
</script>
<body>
<textarea id="tx">Value Of Textarea</textarea>
<input id="button" value="Get Value" onclick="getValueTextarea()">
</body>

Retrieve value of slider

I am trying after reading manual get slider working. It returns Null. What I am doing wrong? How do I get current value form slider?
$('#slider-fill').slider();
var value = $('#slider-fill').slider("option", "value");
$(document).on('vclick', '#test', function(){
alert(value);
});
<input name="slider" id="slider-fill" value="1" min="1" max="10" step="1" data-highlight="true" type="range">
sdfsdf
Fiddle: http://jsfiddle.net/smatisen/eupjvf2x/
You want to use jQuery .val() -- which gets the value of an input.
alert($('#slider-fill').val());
http://jsfiddle.net/TheFiddler/eupjvf2x/2/
You shouldn't need the value var at all, I don't think.

Can't get onclick on a button to be accepted

I currently have a link in the below form:
Change
In order to fit the look of the site in which I'm adding this link, I want to change it to a button input, as so:
<input type="button" value="Change" onclick="changeNumbers('Numbers', '#Url.Action("ChangeNumbers")')" />
However, I'm running into a snag with this second form: the single quotes around #Url.Action("ChangeNumbers") are being flagged as Unterminated string constant. Can anyone tell me what I'm doing incorrectly and how to fix it?
EDIT
It didn't occur to me to just try the page - it looks like the second form works. So now my question is - why is Visual Studio flagging this as incorrect?
You're not doing anything "incorrectly" per se, it's just that Razor isn't perfect, and things like quotes within quotes tend to cause it to freak.
One quick fix would be to store the URL in a variable and then use the variable:
#{ var url = Url.Action("ChangeNumbers"); }
<input type="button" value="Change" onclick="changeNumbers('Numbers', '#url')" />
However, an even better fix is to not use the onclick attribute at all. Put this where it belongs: in JS.
<script>
$('#myButton').on('click', function () {
changeNumbers('Numbers', '#Url.Action("ChangeNumbers")');
});
</script>
Used jQuery above, since it's included in MVC by default
I've found that to make Visual Studio happy in this scenario, the easiest thing to do is simply change the <input /> element to a <button></button> element and the error will resolve itself:
<button type="button" onclick="changeNumbers('Numbers', '#Url.Action("ChangeNumbers")')">Change</button>
Otherwise, to continue using an <input /> the markup will need to be changed to the following:
<input type="button" value="Change" onclick="#("changeNumbers('Numbers', '" + Url.Action("ChangeNumbers") + "')")" />

POST value of date picked in YUI calendar

I've been looking every where, and the tutorial doesn't seem to work when I use it. I saw something like getfullmonth, getfullyears etc. ... anyway, I'm using this code:
My js:
<script>
YAHOO.namespace("example.calendar");
YAHOO.example.calendar.init = function() {
YAHOO.example.calendar.cal1 = new YAHOO.widget.CalendarGroup("cal1","cal1Container", {PAGES:1});
YAHOO.example.calendar.cal1.render();
}
YAHOO.util.Event.onDOMReady(YAHOO.example.calendar.init);
</script>
And this is my HTML:
<input type="text" value="I WANT TO PUT THE SELECTED DATE HERE" id="datechoix" class="n-input2" name="datechoix" readonly="readonly" />
<div id="cal1Container" style="margin-top:15px;"></div>
Anyone got a good tutorial or a complete answer maybe?
You have to listen to the select-date-event. It fires if a user selects a date and holds the date information as arguments.
See this example:
http://yui.github.io/yui2/docs/yui_2.9.0_full/examples/button/btn_example09.html

Resources