2

I am able to select multiple options that I send from my .jsp file in JSON format. However, when I want to SUBMIT/access the values from the text input element "tokenize", I get a undefined output. I am a novice to java script and so what to touch and what not to touch.

Q: Could someone provide/point me to some detail on how to achieve this at the earliest?? Is there something missing below?

Thnx in Advance, Aditya

Note: The body tag got split into a separate code block. Pls donot get confused.

<html>
<head>
<link rel="stylesheet" type="text/css" href="css/jquery.autocomplete.css" />
<script src="http://www.google.com/jsapi"> </script>  
<script>  
    google.load("jquery", "1");
</script>
<script type="text/javascript" src="js/jquery.autocomplete.js"></script>

    <script type="text/javascript" src="js/jquery.tokeninput.js"></script>
    <link rel="stylesheet" href="css/token-input.css" type="text/css" />
    <link rel="stylesheet" href="css/token-input-facebook.css" type="text/css" />

    <style>
        input {
            font-size: 120%;
        }
    </style>
    <script type="text/javascript">
        function showList()
        {
            t = document.getElementById('tokenize').valueOf();
            alert(t); //DISPLAYS 'undefined' <- LOOK HERE
        }
    </script>

<h1>Jquery Tokenizing Autocomplete Input</h1>

<form name="myForm">
    <div>
        <h2>List style</h2>
        <input type="text" id="tokenize" name="blah"/> <br>
        <input type="submit" value="Parse" onClick="showList()"/>
    </div>
    <div>
        <h2>Facebook style</h2>
        <input type="text" id="tokenize2" name="blah2" />
    </div>
</form>

<!-- <script type="text/javascript">
    $("#country").autocomplete("getData.jsp",
     {'multiple': true, 'multipleSeparator': ','});
</script> -->

<script type="text/javascript">
$(document).ready(function() {
    $("#tokenize").tokenInput("getData.jsp", {
        hintText: "Type in the names of your favorite TV shows",
        noResultsText: "No results",
        searchingText: "Searching..."
    });

    $("#tokenize2").tokenInput("getData.jsp", {
        classes: {
            tokenList: "token-input-list-facebook",
            token: "token-input-token-facebook",
            tokenDelete: "token-input-delete-token-facebook",
            selectedToken: "token-input-selected-token-facebook",
            highlightedToken: "token-input-highlighted-token-facebook",
            dropdown: "token-input-dropdown-facebook",
            dropdownItem: "token-input-dropdown-item-facebook",
            dropdownItem2: "token-input-dropdown-item2-facebook",
            selectedDropdownItem: "token-input-selected-dropdown-item-facebook",
            inputToken: "token-input-input-token-facebook"
        }
    });
});
</script>

2 Answers 2

2
<script type="text/javascript">
    function showList()
    {
        //INSTEAD OF: t = document.getElementById('tokenize').valueOf();
        var t = $('#tokenize').val();
        alert(t);
    }
</script>
Sign up to request clarification or add additional context in comments.

3 Comments

Yeah! Thanks lukiffer! I was now able to do it. Two things required are: 1. Need to replace GET with a POST in the .js file included. 2. Yes, use ".val()". You get the answer. Thanks again!!
Not to be trolling for rep points, but could you use the checkbox (left) to mark as the answer if it was helpful in resolving your issue? Cheers mate!
@lukiffer, may I ask u to have a visit at stackoverflow.com/questions/9141176/…? just expecting u to contribute there in a question about tokeninput. n i donno whether such a request is acceptable in SOF
0

Instead of:

var t = document.getElementById('tokenize').valueOf() 

use

var t = document.getElementById('tokenize').value;

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.