Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
187
rated 0 times [  194] [ 7]  / answers: 1 / hits: 69907  / 11 Years ago, sat, august 10, 2013, 12:00:00

I tried connecting the first text box, so it would turn it into a URL, and then when 'search' is clicked, it would jump to that website, not sure if it's impossible, or i'm just clueless, but would really appreciate some help, thank you in advance!




<html>

<head>
</head>

<body>
<script type=text/javascript>
function link() {
var link_s = document.getElementById('link_id').value;
document.getElementById('link_str').innerHTML = link_s.link()
}
</script>

<h2> Search box </h2>
<input type='text' id='link_id'>
<input type='button' id='link_str' value='Search' onClick='link()'>
</body>
<html>




More From » html

 Answers
21

Try this JavaScript:



function goTo()
{
location.href = document.getElementById('link_id').value;
}


and change the onclick in the HTML:



<input type='text' id='link_id'>
<input type='button' id='link' value='Search' onClick='javascript:goTo()'>


Edit:



If you want to follow the unobtrusive JavaScript way, you would move the onclick completely into your JavaScript code, and remove it in the HTML:



document.getElementById('link').onclick = function()
{
location.href = document.getElementById('link_id').value;
};

[#76409] Friday, August 9, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jazminuniquer

Total Points: 63
Total Questions: 121
Total Answers: 96

Location: Cambodia
Member since Thu, May 21, 2020
4 Years ago
;