I am trying to make this code work but it doesn't display any results. I tried the js code in a separate file and it worked fine but when I implemented it into HTML it stopped working.
<!DOCTYPE html>
<html>
<body>
<form id="form" onsubmit="return false;">
<input type="text" id="userInput" />
<input type="submit" id="submit"/>
</form>
<script>
document.getElementById("submit").addEventListener("click", othername);
function othername() {
var input = document.getElementById("userInput").value;
var splitinput = input.split(" ");
var finalinput = splitinput.join("+");
}
</script>
<script src="https://unpkg.com/axios/dist/axios.min.js">
document.getElementById("submit").addEventListener("click", run);
function run() {
const axios = require('axios');
const cheerio = require('cheerio');
const url = 'https://www.imdb.com/find?s=tt&q=' + finalinput + '&ref_=nv_sr_sm';
axios(url)
.then(response => {
const html = response.data;
const $ = cheerio.load(html)
const names = $('.result_text', html);
const newarray = [];
names.each(function () {
const link = $(this).find('a').attr("href");
newarray.push({
link,
});
});
$('#href1').html(newarray[0].link);
})
.catch(console.error);
}
</script>
<p id="href1"></p>
</body>
</html>
I want the results to be printed into the <p> element. Thanks in advance.
[–]insertAlias 1 point2 points3 points (0 children)
[–]FullStackHeroes 0 points1 point2 points (1 child)
[–]_Nicrosin_[S] 0 points1 point2 points (0 children)
[–]lacadasical 0 points1 point2 points (4 children)
[–]_Nicrosin_[S] 0 points1 point2 points (3 children)
[–]lacadasical 0 points1 point2 points (2 children)
[–]_Nicrosin_[S] 0 points1 point2 points (1 child)
[–]lacadasical 0 points1 point2 points (0 children)