I am new to JavaScript and am looking for some help. I am trying to make a JSON request based on textbox input. I want the text form the box to be a part of the request, however I cannot make the text be a string so that it can be used for the JSON request. What am I doing wrong?
Here is my code:
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
</head>
<body>
<p id="syno"></p>
<form name="test">
<input type="text" name="Edit"> <!-- where i input a word-->
<input type="button" value="Test" onClick="gettext()"><!-- test button-->
<input type="text" name="Edit2" value="power" readonly style="border:1px solid white">
</form>
<script>
function gettext() {
document.test.Edit2.value = document.test.Edit.value;
document.test.Edit2("Edit2").value = document.test.Edit.value;
}
var apiKey = '0771a4c95ca7e23d41e33f67a1da0000/';
var txtjson = '/json';
var f = document.test.Edit2.value;
var apiUrl = 'http://words.bighugelabs.com/api/2/' + apiKey + f + txtjson;
$.ajax({
url: apiUrl,
type: "GET",
dataType: 'json',
success: parseWord
});
function parseWord(data) {
$('#syno').text(data.noun.syn);
}
</script>
</body>
</html>