Introduction
Introduction Statistics Contact Development Disclaimer Help
datalist: improve example and pass input element to url function - jscancer - J…
git clone git://git.codemadness.org/jscancer
Log
Files
Refs
README
LICENSE
---
commit b4ee6b2cb8c463a9127067e53c704f81d39f4340
parent 19e7513dd8e720e3aff80e70cbcaf38608a3efd7
Author: Hiltjo Posthuma <[email protected]>
Date: Tue, 13 Jun 2023 22:41:10 +0200
datalist: improve example and pass input element to url function
Diffstat:
M datalist/datalist.js | 4 ++--
M datalist/example.html | 9 ++++++---
2 files changed, 8 insertions(+), 5 deletions(-)
---
diff --git a/datalist/datalist.js b/datalist/datalist.js
@@ -56,7 +56,7 @@ function datalist_init(input) {
};
if (url.length || urlfn.length) {
- urlfn = urlfn.length ? window[urlfn] : function(s) {
+ urlfn = urlfn.length ? window[urlfn] : function(s, input) {
return url + encodeURIComponent(s);
};
@@ -65,7 +65,7 @@ function datalist_init(input) {
datalist_match = function(s, fn, ev) {
clearTimeout(timer);
- var requrl = urlfn(s);
+ var requrl = urlfn(s, input);
if (requrl === prevurl) {
fn(prevmatches);
return;
diff --git a/datalist/example.html b/datalist/example.html
@@ -30,17 +30,20 @@
<p>Using XMLHttpRequest + JSON:</p>
<label for="remote">OS: </label>
-<input type="text" placeholder="Select OS..." value="" data-url="example-data.…
+<input type="text" placeholder="Select OS..." value="" data-url="example-data.…
<p>Using XMLHttpRequest + custom URL function + JSON:</p>
<label for="remotecustom">OS: </label>
-<input type="text" placeholder="Select OS..." value="" data-urlfn="custom_urlf…
+<input type="text" placeholder="Select OS..." value="" data-urlfn="custom_urlf…
+
+<label for="remotecustom2">OS: </label>
+<input type="text" placeholder="Select OS..." value="" data-urlfn="custom_urlf…
</form>
<script type="text/javascript">
-function custom_urlfn(s) {
+function custom_urlfn(s, input) {
return "example-data.json?q=" + encodeURIComponent(s);
};
</script>
You are viewing proxied material from codemadness.org. The copyright of proxied material belongs to its original authors. Any comments or complaints in relation to proxied material should be directed to the original authors of the content concerned. Please see the disclaimer for more details.