Forum Moderators: open
When I do this, it writes the values...
document.writeln(document.getElementById('choose').value);
document.writeln(document.getElementById('searchfield').value);
Here's the full code. If I ask it to alert(searchsite) it tells me undefined. It'll tell me the same thing for searchstring or searchsite.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Form Test</title>
</head><script type="text/javascript">
var searchstring = document.getElementById('searchfield').value;
var searchsite = document.getElementById('choose').value;
var searchurl = searchsite + searchstring;
function gosearch() {
onsubmit = window.open(searchsite);
}
</script>
<body>
<strong>Search:</strong>
<select name="choose" id="choose">
<option value="http://www.google.com/search?q=">Google</option>
<option value="http://search.yahoo.com/search?p=">Yahoo!</option>
<option value="http://search.live.com/results.aspx?q=">Microsoft</option>
</select>
<input type="text" name="searchfield" id="searchfield" value="asdf" />
<input type="button" name="gobutton" id="gobutton" value="Go!" onclick="gosearch();" />
</body>
</html>
For background, I'm trying to work around an ASP.NET issue that only lets you have one form on a page. I don't have any access to that, and I know nothing about ASP.NET. I just need to send a javascript example to the developer who is working with it.
<script type="text/javascript">
function gosearch() {
var searchstring = document.getElementById('searchfield').value;
var searchsite = document.getElementById('choose').value;
var searchurl = searchsite + searchstring;
window.location.href = searchurl;
}
</script>