Jump to content

Search the Community

Showing results for tags 'callbacks'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • W3Schools
    • General
    • Suggestions
    • Critiques
  • HTML Forums
    • HTML/XHTML
    • CSS
  • Browser Scripting
    • JavaScript
    • VBScript
  • Server Scripting
    • Web Servers
    • Version Control
    • SQL
    • ASP
    • PHP
    • .NET
    • ColdFusion
    • Java/JSP/J2EE
    • CGI
  • XML Forums
    • XML
    • XSLT/XSL-FO
    • Schema
    • Web Services
  • Multimedia
    • Multimedia
    • FLASH

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


AIM


MSN


Website URL


ICQ


Yahoo


Jabber


Skype


Location


Interests


Languages

Found 2 results

  1. My website needs to use a date picker to choose first and last dates of a rental period. I chose TheDatePicker because it said it was pure JS and easy to use. The picker for the first date works fine. I am finally able to make the MinDate 10 days from the current date, as intended. Once the first date is chosen, I need to make it the MinDate for the second chooser. I can't seem to find the correct code to do that. Do I need to use a callback? Do I have to set a listener? The docs for TheDatePicker show code for doing that, but that code is in TypeScript rather than straight JS, and I can't figure out how to implement it. Can someone point me to an example, or suggest a different picker where this is easier? Here is my code: <tr> <td style="text-align:center"> <div id="input-wrapper" class="w3-container" style="text-align:center"> <input id="date1" type="text" class="form-control w3-show-inline-block w3-border") style="width:60%; min-width:11ch"> <script> (function () { // This code works as intended. const input = document.getElementById('date1'); const datepicker = new TheDatepicker.Datepicker(input); datepicker.options.setInputFormat("Y, m, d"); datepicker.options.setMinDate("+ 10 days"); datepicker.options.setDropdownItemsLimit(20); datepicker.render(); })(); </script> </div> </td> <!-- 2ND DATE FIELD --> <td id="wrapper2"> <div class="w3-container" style="text-align:center"> <input id="date2" type="text" placeholder="Last show" class="form-control w3-right w3-border" style="width:60%; min-width:11ch"> <script> (function () { const input2 = document.getElementById('date2'); const datepicker2 = new TheDatepicker.Datepicker(input2); //This code obviously needs to go somewhere else, because it can't run until date1 is chosen. var d = new Date(document.getElementById("date1").value); datepicker2.options.setMinDate(d.toDateString() //(I realize this code won't work anyway, but I can fix that. My question is how to access it.) datepicker2.render(); })(); </script> </div> </td> </tr> This is what's shown in the docs, but I can't figure out how to implement it. // Callback to be called just before the datepicker is opened or closed. // An Event instance and a boolean telling whether datepicker was opened (true) or closed (false) are given on input. // If callback returns false, action stops and datepicker will not be opened / closed. public onBeforeOpenAndClose(listener: OpenAndCloseListener): void { this.onEvent_(EventType_.BeforeOpenAndClose, listener as AnyListener); } public offBeforeOpenAndClose(listener: OpenAndCloseListener | null = null): void { this.offEvent_(EventType_.BeforeOpenAndClose, listener); } // Callback to be called immediately after the datepicker is opened or closed. // An Event instance and a boolean telling whether datepicker was opened (true) or closed (false) are given on input. public onOpenAndClose(listener: OpenAndCloseListener): void { this.onEvent_(EventType_.OpenAndClose, listener as AnyListener); } public offOpenAndClose(listener: OpenAndCloseListener | null = null): void { this.offEvent_(EventType_.OpenAndClose, listener);
  2. Hello. I have a problem with a function that contains a callback. The problem is, when I execute it the first time, it works without no problem, but the second time, the callback is executed twice: first with the first value and later with the second value. I post the code and an example of running Code of the function: function titulo(terminoTitulo) { console.log("titulo():"); console.log("titulo(): Fuera del callback: " + terminoTitulo); consultar_titulo(terminoTitulo, function (titulo) { console.log("titulo(): termino: " + terminoTitulo); console.log("titulo(): Dentro del Callback"); console.log("titulo(): "+titulo.length); }); Code of the proxy that receives the parameters and calls to a nodejs server: function consultar_titulo(titulo_consulta, callback) { var socket = io.connect('http://localhost:8080'); socket.emit('consultar_titulo', { "titulo_consulta": titulo_consulta }); console.log("proxy(): Emitida la consulta"); socket.on('respuesta_consultar_titulo', function (data) { console.log("proxy(): Estoy en el proxy dentro del callback"); callback(data.respuesta_emit); });} //consultar_titulo() Example of running. titulo():titulo(): Fuera del callback: bbb proxy(): Emitida la consulta proxy(): Estoy en el proxy dentro del callback titulo(): termino: aaa titulo(): Dentro del Callback titulo(): 0 proxy(): Estoy en el proxy dentro del callbacktitulo(): termino: bbb titulo(): Dentro del Callbacktitulo(): 0 In this example the first time, the user introduced "aaa", and the second time "bbb". As can see, the function is called once but when the callback is executed two times. Regards
×
×
  • Create New...