1

This is the standard Jquery Autocomplete code.

<script>
    $(function() {
        var availableTags = [
            "JavaScript",
            "C#",
            "VB.NET",
            "ASP.NET"
        ];
        $( "#tags" ).autocomplete({
            source: availableTags
        });
    });
</script>

Let's say I'm able to fill an HTML DOM (delimited text or a grid made of table/tr/td) with data through server-side (ASP.NET/PHP). How would it be possible to "read" through it and store it in "availableTags[]" for Jquery Autocomplete to use?

And if I hide (display:none; perhaps) this DOM Element, will Jquery still be able to "see" it?

0

2 Answers 2

1

Why not have the server-side code simply output the javascript declaration of the array right out onto the page? That way you wouldn't need to parse it, and your server-side code is going to be effectively the same in either instance.

Sign up to request clarification or add additional context in comments.

Comments

1

I would prefer the hidden field solution if you are not presenting the data visually. No need to build a table if you hide (even though jquery will be able to work with, it's just a visual hiding, it's still in the DOM).

The .map() function followed by .toArray() generates a javascript array:

<table>
    <tr><td>Value1</td></tr>
    <tr><td>Value2</td></tr>
    <tr><td>Value3</td></tr>
    <tr><td>Value4</td></tr>
    <tr><td>Value5</td></tr>
</table>

var availableTags = $('td').map(function() { return $(this).text(); }).toArray();

Or for a delimited text into an hidden field:

<input type="hidden" id="myhiddenfield" value="value1|value2|value3" />

var availableTags = $('#myhiddenfield').val().split('|');

In action here: Jsfiddle

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.