<textarea name="comment" cols="55" rows="8" onclick="this.value=''">Please feel free to leave a comment or a question here</textarea>
<html>
<head><title>Test</title>
<script type="text/javascript">
var flag = true ;
function clear_me(){
if( flag ){
var t = document.getElementById( 'comm' );
t.defaultValue = '' ;
flag = false;
}
}
</script>
<body>
<textarea name="comment" cols="55" rows="8" id="comm"
onfocus="clear_me()" ;>Please feel free to leave a comment or a question here</textarea>
</body>
</html>
Ha, how could I forget that.
You mean something like this:Hmmm.....under further testing, using 'defaultValue' seems to remove the need for the flag, while 'value' does require it.
<textarea name="comment" cols="55" rows="8" id="comm"
onfocus="if(this.value == this.defaultValue){this.value = ''}">Please feel free to leave a comment or a question here</textarea>
if (document.orderform.terms.checked== false) {
alert("You must agree to our terms and conditions below an order can be processed")
return false
}
, [html] or [code] tags (as appropriate) to separate and format code:
[code]if (document.orderform.terms.checked== false) {
alert("You must agree to our terms and conditions below an order can be processed");
return false;
}[/code]
[quote="focus, post: 681413"]What do you mean by DOM objects?[/QUOTE]
The [URL="http://www.w3.org/DOM/"]Document Object Model[/URL] is the standard that defines the capabilities of document objects (e.g. HTML elements and attributes). In this case, accessing the form with [FONT="Courier New"]document.orderform[/FONT] isn't covered by the DOM. It will work in IE, but fail in other browsers. [FONT="Courier New"]document.forms.orderform[/FONT] is the cross browser way of accessing the form, and is covered in DOM levels 1 and 2.
However, a better approach is to pass the form to the validation function:
[html]<form name="orderForm" action="..." onsubmit="return validate(this)">
...[/html]
[code]function validate(form) {
...
// comparisons with 'false' is almost always bad form
if (! form.elements.terms.checked) {
// by abstracting out the alert function, you can display notices
// in whichever manner you wish: alerts, [URL="http://www.google.com/search?q=inline+form+validation"]in-line messages[/URL], ...
notice(form.elements.terms, 'You must agree to our terms and conditions [COLOR="red"]before[/COLOR] an order can be processed');
form.elements.terms.focus();
return false;
}
return true;
}[/code]
<?php
function is_valid_email($from_email)
{
return preg_match('#^[a-z0-9.!\#$%&\'*+-/=?^_`{|}~]+@([0-9.]+|([^\s\'"<>]+\.+[a-z]{2,6}))$#si', $from_email);
}
$headers = "From:xxxx@hotmail.com\r\n";
$headers .= "MIME-Version: 1.0\r\n"
. "Content-Type: text/html; charset=\"iso-8859-1\"\r\n"
. "Content-Transfer-Encoding: 7bit\r\n";
$to_email = xxxx@hotmail.com";
$subject = "Order";
$productid.=$_POST['productid']."\n" ;
$sneakername.=$_POST['sneakername']."\n" ;
$fullname.=$_POST['fullname']."\n" ;
$size.=$_POST['size'] ."\n" ;
$address.=$_POST['address'] ."\n" ;
$suburb.=$_POST['suburb']."\n" ;
$city.=$_POST['city']."\n" ;
$state.=$_POST['state'] ."\n" ;
$postcode.=$_POST['postcode']."\n" ;
$phone2.=$_POST['phone2']."\n" ;
$phone.=$_POST['phone'] ."\n" ;
$from_email.=$_POST['from_email']."\n" ;
$payment.=$_POST['payment']."\n" ;
$comment.=$_POST['comment']."\n" ;
$message = "
<body>
<b>Product ID:</b><br>
$productid
<br> <br>
<b>Sneaker Name:</b><br>
$sneakername
<br> <br>
<b>Full Name:</b><br>
$fullname
<br> <br>
<b>Shoe Size:</b><br>
$size
<br> <br>
<b>Street Address:</b><br>
$address
<br> <br>
<b>Suburb:</b><br>
$suburb
<br> <br>
<b>City:</b><br>
$city
<br> <br>
<b>State:</b><br>
$state
<br> <br>
<b>Post Code:</b><br>
$postcode
<br> <br>
<b>Contact Number</b><br>
$phone
<br> <br>
<b>Email:</b><br>
$from_email
<br> <br>
<b>Payment Method:</b><br>
$payment
<br> <br>
<b>Comment:</b><br>
$comment
<br> <br>
<b>Terms & Conditions:</b><br>
I $fullname, have read and agreed with the terms & conditions.
</body>
";
$sent = mail($to_email, $subject, $message, $headers) ;
if($sent)
{print "Your mail was sent successfully."; }
else
{print "We encountered an error sending your mail"; }
?>
One very important reason to do this is to prevent an injection attack. Make sure $from_email is sanitized. There isn't much damage possible with an e-mail injection, but there is some.But make sure the $from_email is valid.