form submit with enter key pressed or click submit

2019-09-21 07:27发布

问题:

I have a form that I want the user the be able to use the

Enter key or Click on the button to submit it.

Here is the code I have:

<html>
<head>
<link href="style.css" rel="stylesheet" type="text/css" />
<title>Blah</title>
<script type="text/javascript">
function SetSrc()
{
document.getElementById("myIfreme1").src = 'http://' +   
document.getElementById("txtSRC").value;
}
</script>
</head>
<body>
<form>
Enter URL:  http://
<input type="text" id="txtSRC" />
<input type="button" value="GO" onclick="SetSrc()" />
</form>
<div style="clear:both">320 width</div>
<iframe id="myIfreme1" src="" frameborder="0" marginwidth="0" height="480" width="320" 
scrolling="yes"></iframe>
</body>
</html>

Thanks for your help.

回答1:

Your form needs a submit button... so add <input type="submit" value="Submit"/> inside your form.

You should check out these articles on HTML Forms...