• 0

Sumbit using Enter key with JavaScript


Question

Hello,

I was wondering if it is possible to get the following to submit to a shoutbox using the enter key rather than clicking submit. If anyone can help I'd really appreciate it.

<script language="JavaScript" type="text/javascript">
<!--

function chkFormularShoutBox() {
    if(document.getElementById('shoutbox_name').value == ""){
        alert('%enter_name%');
        document.getElementById('shoutbox_name').focus();
        return false;
    }
    if(document.getElementById('shoutbox_message').value == "" || document.getElementById('shoutbox_message').value == "Message"){
        alert('%enter_message%');
        document.getElementById('shoutbox_message').focus();
        return false;
    }
    return true;
}
-->
</script>
<script language="JavaScript" type="text/javascript">
<!--
var xmlhttp;




function stateChanged()
{
if (xmlhttp.readyState==4)
  {
    var show= xmlhttp.responseText.split("||<img");
  document.getElementById("shoutbox").innerHTML=show[0];
document.getElementById("captcha1").innerHTML="<img" + show[1];
  }
}

function shout()
{
xmlhttp=GetXmlHttpObject();
if (xmlhttp==null)
  {
  alert ("Browser does not support HTTP Request");
  return;
  }
var name = document.getElementById('shoutbox_name').value;
var message = document.getElementById('shoutbox_message').value;
var captcha = document.getElementById('captcha2').value;
var captcha_hash = document.getElementById('captcha_hash2').value;
xmlhttp.onreadystatechange=stateChanged;
xmlhttp.open("GET",'shout1.php?name='+name+'&message='+message+'&captcha='+captcha+'&captcha_hash='+captcha_hash,true);
xmlhttp.send(null);
document.getElementById('shoutbox_name').value="$name";
document.getElementById('shoutbox_message').value="Message";
document.getElementById('captcha2').value="";
}


function GetXmlHttpObject()
{
if (window.XMLHttpRequest)
  {
  // code for IE7+, Firefox, Chrome, Opera, Safari
  return new XMLHttpRequest();
  }
if (window.ActiveXObject)
  {
  // code for IE6, IE5
  return new ActiveXObject("Microsoft.XMLHTTP");
  }
return null;
}
-->
</script>

<script language="JavaScript" type="text/javascript">
<!--


fetch('shoutbox_content.php', 'shoutbox', 'replace', 'time', $refresh);
-->
</script>
<div id="shoutbox" style="margin:5px; padding: 8px; width: 195; height: 300px; overflow:auto; text-align: left; background-color: #FFF; border: 1px solid #CCC;"></div>

<div id="captcha1">$captcha_form</div>
<table width="100%" cellspacing="0" cellpadding="0">
<tr>
<td><input type="text" id="shoutbox_name" name="name" size="19" maxlength="255" $name_settings />
<br />
<input type="text" id="shoutbox_message" name="message" size="19" maxlength="255"  value="Message" onfocus="this.value=''" /></td>
<td valign="top"><a onKeyPress="return if(chkFormularShoutBox())+shout();" href="#" onclick="if(chkFormularShoutBox())+shout();" ><img src="design/shout.jpg" /></a></td>
</tr>
</table>

Link to comment
Share on other sites

0 answers to this question

Recommended Posts

There have been no answers to this question yet

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.