d9esco
02-01-2016, 01:41 AM
I have a variable that stores the value of a search box. This value is supposed to represent the id of another element. I want to use the focus command in javascript to focust on the value as an id in the page. how do I do this? This is what I had.
function search(){
var val = document.getElementById('search').value;
val.focus();
}
<body id="body" onload="document.getElementById('title').focus();">
<input value=" Search" id="search" onclick="document.getElementById('search').value=' '"></input>
<button id="button" onclick="search();">Search</button>
function search(){
var val = document.getElementById('search').value;
val.focus();
}
<body id="body" onload="document.getElementById('title').focus();">
<input value=" Search" id="search" onclick="document.getElementById('search').value=' '"></input>
<button id="button" onclick="search();">Search</button>