Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to display Jquery autocomplete result outside autocomplete function
    text
    copied!<p>This HTML code is for picking a date and a destination for the trip. I want to display my result (Destination) outside the autocomplete function. </p> <p>How to call autocomplete result in <code>confirm</code> box (check <code>if else</code> statement in jquery)?</p> <p>Here is my code.</p> <pre class="lang-html prettyprint-override"><code>&lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;title&gt;Pick a Date&lt;/title&gt; &lt;link rel='stylesheet' type='text/css' href="style/jquery-ui.css"/&gt; &lt;script src="script/jquery-1.9.1.js"&gt;&lt;/script&gt; &lt;script src="script/1.10.3-jquery-ui.js"&gt;&lt;/script&gt; &lt;link rel='stylesheet' type='text/css' href='style/stylesheet.css'/&gt; &lt;script type='text/javascript' src='script/script.js'&gt;&lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;div id="header"&gt; &lt;h2&gt;&lt;br/&gt;Select a Destination&lt;/h2&gt; &lt;/div&gt; &lt;div class="left"&gt; &lt;p&gt;Departing: &lt;input type="text" id="departing"&gt;&lt;/p&gt; &lt;/div&gt; &lt;div class="right"&gt; &lt;p&gt;Returning: &lt;input type="text" id="returning"&gt;&lt;/p&gt; &lt;/div&gt;&lt;br/&gt; &lt;div id="main"&gt; &lt;div class="ui-widget"&gt; &lt;label for="tags"&gt;Destination: &lt;/label&gt; &lt;input id="tags"&gt; &lt;button&gt;Submit&lt;/button&gt; &lt;/div&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>Jquery:</p> <pre class="lang-js prettyprint-override"><code>// JavaScript Document $(document).ready(function() { $("#departing").datepicker(); $("#returning").datepicker(); $("button").click(function() { var departing = $("#departing").val(); var returning = $("#returning").val(); var places = ["Canada","China","Chicago","Japan","Germany","London","Moskow","Paris","Phillipins","India","Russia","Srilanka"]; $("#tags").autocomplete({ source: places, select: function(event, ui) { $('#tags').text(ui.item.value); } }); if (departing === "" || returning === "") { alert("Please select departing and returning dates."); } else { confirm("Would you like to go to " + ???? + " on " + departing + " and return on " + returning + "?"); } }); }); </code></pre>
 

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