Note that there are some explanatory texts on larger screens.

plurals
  1. POJQuery Mobile: update select using javascript
    primarykey
    data
    text
    <p>I am trying change a select value with javascript in a phonegap/JQM application. I followed the recommendation to call .selectmenu('refresh') after I changed its value; It get this error:</p> <p>Uncaught cannot call methods on selectmenu prior to initialization; attempted to call method 'refresh'</p> <p>If I remove that call the .val() on the select will change, but the graphic on the screen will not change. The .selectmenu("refresh") is intended to synchronize the graphic with the .val() of the select.</p> <p>Here are two of the resources I am attempting to make use of: <a href="http://jquerymobile.com/demos/1.0a3/#docs/forms/plugin-eventsmethods.html" rel="noreferrer">http://jquerymobile.com/demos/1.0a3/#docs/forms/plugin-eventsmethods.html</a> <a href="http://jquerymobile.com/test/docs/forms/forms-selects.html" rel="noreferrer">http://jquerymobile.com/test/docs/forms/forms-selects.html</a></p> <p>I am new phonegap and JQM.</p> <p>Here is sample code that attempts to flips the select every three seconds:</p> <pre><code>&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"&gt; &lt;html&gt; &lt;head&gt; &lt;meta name="viewport" content="width=default-width; user-scalable=no" /&gt; &lt;meta http-equiv="Content-type" content="text/html; charset=utf-8"&gt; &lt;title&gt;Demo Error&lt;/title&gt; &lt;script type="text/javascript" charset="utf-8" src="phonegap.js"&gt;&lt;/script&gt; &lt;script type="text/javascript" charset="utf-8"&gt; function onBodyLoad() { document.addEventListener("deviceready",onDeviceReady,false); for (i=1;i&lt;10;i++) { setTimeout('changeProduct()',i*3000); } } function changeProduct() { if ($("#product").val() == 'S') { $("#product").val('M'); } else { $("#product").val('S'); } console.log("calling selectmenu refesh change to " + $("#product").val()); $("#product").selectmenu('refresh', true); } /* When this function is called, PhoneGap has been initialized and is ready to roll */ function onDeviceReady() { // do your thing! } &lt;/script&gt; &lt;link rel="stylesheet" href="jquery.mobile-1.0a3.css" /&gt; &lt;link rel="stylesheet" href="quote.css" /&gt; &lt;script src="jquery-1.5.min.js"&gt;&lt;/script&gt; &lt;script src="jquery.mobile-1.0a3.js"&gt;&lt;/script&gt; &lt;/head&gt; &lt;body onload="onBodyLoad()"&gt; &lt;div id="page1" data-role="page"&gt; &lt;div data-role="content"&gt; &lt;div id="product-all" data-role="fieldcontain"&gt; &lt;label for="product"&gt;Product:&lt;/label&gt; &lt;select data-role="slider" name="product" id="product" value="S"&gt; &lt;option id="one" value="S"&gt;Single&lt;/option&gt; &lt;option id="two" value="M" selected="selected"&gt;Multi&lt;/option&gt; &lt;/select&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;/body&gt; &lt;/html&gt; </code></pre>
    singulars
    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.
 

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