Computing.Net > Forums > Web Development > Make Submt Button Work

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Make Submt Button Work

Reply to Message Icon

Name: You know who we are.
Date: April 3, 2009 at 00:10:57 Pacific
OS: Windows Vista
CPU/Ram: 2GB
Product: Microsoft / Vista
Subcategory: Javascript/Ajax
Comment:

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:

<!-- TWO STEPS TO INSTALL CLICK TO SUBMIT:

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 -->

<HEAD>

<SCRIPT LANGUAGE="JavaScript">
<!-- Original: Shawn Hafen (shafen@mail.com) -->
<!-- Web Site: http://shafen0.tripod.com/index.html -->

<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->

<!-- 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 -->
</script>

</HEAD>

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

<BODY>

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

<center>
Free JavaScripts
provided

by The JavaScript
Source

</center>

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



Sponsored Link
Ads by Google

Response Number 1
Name: shutat
Date: April 3, 2009 at 03:51:11 Pacific
Reply:

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.

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

   document.getElementById("mydiv").innerHTML = txt;
}
</script>
</head>
<body>
<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);">
</form>
</body>
</html>

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


0

Response Number 2
Name: You know who we are.
Date: April 3, 2009 at 16:20:47 Pacific
Reply:

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?


0

Response Number 3
Name: shutat
Date: April 3, 2009 at 17:01:12 Pacific
Reply:

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.

<?php

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);
}
?>
<html>
<head>
<title>...</title>
</head>
<body>
<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">
</form>
.... other document parts
</body>
</html>

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.


0

Response Number 4
Name: You know who we are.
Date: April 3, 2009 at 17:32:13 Pacific
Reply:

Thank you, that worked. Do you know how I can put a
search feature in my website?


0

Response Number 5
Name: You know who we are.
Date: June 5, 2009 at 03:32:58 Pacific
Reply:

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?


0

Related Posts

See More



Response Number 6
Name: shutat
Date: June 7, 2009 at 03:50:46 Pacific
Reply:

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.


0

Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Web Development Forum Home


Sponsored links

Ads by Google


Results for: Make Submt Button Work

Flash Buttons need tp be clicked IE www.computing.net/answers/webdevel/flash-buttons-need-tp-be-clicked-ie/3188.html

Buttons with frames help www.computing.net/answers/webdevel/buttons-with-frames-help/528.html

Flash Buttons and Frames www.computing.net/answers/webdevel/flash-buttons-and-frames/1837.html