Using jQuery tokeninput from loopj.com
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-faceb开发者_如何学运维ook",
inputToken: "token-input-input-token-facebook"
}
});
});
</script>
<script type="text/javascript">
function showList()
{
//INSTEAD OF: t = document.getElementById('tokenize').valueOf();
var t = $('#tokenize').val();
alert(t);
}
</script>
Instead of:
var t = document.getElementById('tokenize').valueOf()
use
var t = document.getElementById('tokenize').value;
精彩评论