Solved Make Submt Button Work

Microsoft / Vista
April 3, 2009 at 00:10:57
Specs: Windows Vista, 2GB
Hello, I am trying to let people post comments on my website, so I am using this code for a 'submit comment'does anyone know how make the comment appear on the page immediately, or even just sent to my mail so I can put it in the *.html document? Would I need a *.php for the first one, if so can you just show me how to make it go to my mail? Also one more thing, what can I do to make the textbox larger? Thank you for your help. This is the code that I currently have:


1. Copy the coding into the HEAD of your HTML document
2. Add the last code into the BODY of your HTML document -->

<!-- STEP ONE: Paste this code into the HEAD of your HTML
document -->


<!-- Original: Shawn Hafen ( -->
<!-- Web Site: -->

<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! -->

<!-- Begin
function onKeyPress () {
var keycode;
if (window.event) keycode = window.event.keyCode;
else if (e) keycode = e.which;
else return true;
if (keycode == 13) {
alert("Please Click on the Submit button to send this");
return false
return true
document.onkeypress = onKeyPress;
// End -->


<!-- STEP TWO: Copy this code into the BODY of your HTML
document -->


<input type="text">
<input type=submit>

Free JavaScripts

by The JavaScript


<!-- Script Size: 1.09 KB -->

See More: Make Submt Button Work

Report •

April 3, 2009 at 03:51:11
✔ Best Answer
Q1) if you put an element such as a <p>, <div>, <input>, etc and give it a unique id, then during the button's onclick event, you can add the comment directly to the page... provided that is what you want to do. I think the code you've got is missing something though; the onclick event handler seems to be missing.

<script language="javascript">
function showMsg(txt) {

   document.getElementById("mydiv").innerHTML = txt;
<div id="mydiv"></div>
<form name="myform">
<input name="txtbox" value="sometext" type="text">
<input value="submit" type="button" onclick="showMsg(document.myform.txtbox.value);">

Q2) if you'd like to email it, then you'll have to change things a bit. I'd scrap the javascript myself and just use php. Here's a resource that you might want to mill over. It deals with php forms and sending mail.

Q3) what do you mean by making the textbox larger? If you need a longer box, then use the size="num" property of the input. <input name="sometext" size="100" maxlength="127" type="text"> or if you need a text input field that spans multiple lines, then go with textarea: <textarea name="sometext" rows="5" cols="80"></textarea>

Hope that helps

Report •

April 3, 2009 at 16:20:47
Thank you that did help, but I think that I want it sent to
my email so I can review the comment, how would I make
the text be sent to my email without having to open an
email dialog?

Report •

April 3, 2009 at 17:01:12
No worries; I get some practice too. :)

What you can do is create a php page instead of using an html version. Your content would be the same, but you'd have a comment form somewhere.


if(isset($_POST["cmd"]) && $_POST["cmd"] === "Submit") {
   $name = "your name";
   $from = "your email address"; // shows as from
   $send = "your email address";  // who it's going to
   $mbody = html_entity_decode($_POST["comment"], ENT_QUOTES);
   $subject = "comment from user"; // anything you want
   $header = "FROM: " . $name . " <" . $from . ">\r\n";

   mail($send, $subject, $mbody, $header);
<p>Have a comment?</p>
<form action="<?php echo $_SERVER["PHP_SELF"];?>" method="post">
<textarea name="comment" rows="10" cols="30"></textarea>
<input name="cmd" value="Submit" type="submit">
.... other document parts

Hopefully, that will run without errors, but this little input box makes it hard to read code sometimes. :) If you need further help, just post away... I'm sure someone will be able to help you out.

One thing to be aware of, when you send an email, the mail function returns a boolean (true or false). If true, it only indicates that the function succeeded; it does not mean that the email will be delivered.

Good luck.

Report •

Related Solutions

April 3, 2009 at 17:32:13
Thank you, that worked. Do you know how I can put a
search feature in my website?

Report •

June 5, 2009 at 03:32:58
Is the file supposed to be saved as a *.php or *.html, because when I open the *.php in my web browser, it just downloads the *.php. Do I keep it as *.html but just add the php tags?

Report •

June 7, 2009 at 03:50:46
It's a php script, so you'd need to have a server running php in order for it to work. If you're trying to run the file locally (on a machine that isn't running a web server enabled with php), then the browser will spit out the source code as text.

If you're running it from a website that has php enabled, then check the permission... the script may not have execute permission. However, I'd think you'd get some sort of redirect page error or maybe an internal server error type of response.

If you're running the script on a free host or something, then it may not have php enabled or you may be serving the file from a folder that isn't php enabled. In this case, contact your host's support.

Hope that helps.

Report •

Ask Question