Note that there are some explanatory texts on larger screens.

plurals
  1. POjQuery mobile: data-search value returns empty unless I reload the page
    primarykey
    data
    text
    <p><em>jQuery Mobile 1.3.2:</em> I have a <code>listview</code> with the filter enabled. The page that this is on is loaded via jQuery mobile ajax.</p> <p>My problem is that if I allow it to load via ajax, it detects my <code>keyup</code> event but it does not pull the value of <code>input[data-type="search"]</code>. If I refresh the page using the browser, the script executes perfectly.</p> <p>How can I get this to work while loading the page with AJAX?</p> <p>HTML MARKUP:</p> <pre><code> &lt;ul id="addCompany" style="padding-bottom:10px;" data-role="listview" &gt; &lt;li&gt;&lt;a href="#" onclick="$( 'input[data-type="search"]' ).focus()"&gt;Touch To Add&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt; &lt;div id="listwrap"&gt; &lt;ul data-role="listview" data-autodividers="true" data-filter="true" data-inset="true"&gt; &lt;li&gt;&lt;a href="index.html"&gt;Adam Kinkaid&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt; &lt;/div&gt; </code></pre> <p>jQuery</p> <pre><code> &lt;script&gt; $(document).ready(function(){ var inputVal; $('body').on("keyup",'input[data-type="search"]', function(){ inputVal = $('input[data-type="search"]').val(); if(inputVal===""){ $('#dynamic').html('&lt;li&gt;&lt;a href="#" onclick="$( \'form input\' ).focus()"&gt;Touch To Add&lt;/a&gt;&lt;/li&gt;'); $('#dynamic').listview("refresh"); }else{ $('#dynamic').html('&lt;li&gt;&lt;a href="next.php?i&amp;newitem='+encodeURIComponent($('input[data-type="search"]').val())+'"&gt;Touch Again To Add: '+$('input[data-type="search"]').val()+'&lt;/a&gt;&lt;/li&gt;'); $('#dynamic').listview("refresh"); } }); }); &lt;/script&gt; </code></pre> <p><strong>EDIT</strong>: Note that I can set the value and set the focus on <code>input[data-type="search"]</code> without any hiccups. It is retrieving the value that seems so tricky.</p> <p>I tried adding a class to so that I wouldn't have to call it by data attribute but still couldn't pull the value unless I refreshed the page. Maybe if I inject a function into the input element I can use that to return the value?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload