<script language="javascript" type="text/javascript">
$(function() {
$(".button").click(function() {
var name = $("#Form_Name").val();
var email = $("#Form_Email").val();
var eid = $("#Form_ID").val();
var company = $("#Form_Company").val();
var number = $("#Form_Number").val();
var dataString = 'name='+ name + '&email=' + email + '&eid=' + eid + '&Company=' + company + '&Number=' + number;
//alert (dataString);return false;
$.ajax({
type: "POST",
url: "AJAX_Quote.php",
data: dataString,
success: function() {
tb_remove();
setTimeout("Thanks()", 450);
}
});
});
});
function Thanks()
{
tb_show('Thank You', '#TB_inline?width=400&height=400&inlineId=TBThanks&modal=false', false);
}
jQuery.noConflict();
function clearText(field){
if (field.defaultValue == field.value) field.value = '';
else if (field.value == '') field.value = field.defaultValue;
}
</script>
I know you have to add something like
/* validate function returns true if "ok" false if "bad" */
validate = function(){
/* Check if it is blank */
if (document.getElementById('Form_Name').value = ''){
alert('You must enter a First Name!');
return false;
}
return true;
}
But not quite sure how to do it. Can I just add that code to my existing JS or do I have to completely redo it?
[font=verdana]The problem with making using Javascript to make form fields mandatory is that it’s so easy to bypass – just switch off Javascript and there it goes, and some people will have Javascript turned off anyway. So it depends how bothered you are about the mandatoriness of those fields – is it the end of the world if some people manage to submit the form without them filled in?
If it’s absolutely essential that people fill in all mandatory fields then you need to use a server-side check, rather than relying on client-side controls.
A much easier way to achieve the same effect as Javascript is to use HTML5 forms. Just add the required attribute to any field, and people using Firefox, Chrome, Opera, IE10, Blackberry10 will be unable to submit the form without it filled in (this feature doesn’t work on IE9 and below, or current versions of Safari/iOS or Android).[/font]
Thanks for the replies, Would the HTML5 work on a .php?
In a nutshell, Visitor comes to site, sees a product, then clicks on a “request a quote” button, then the form opens. The form inputs also get put into a database. When they submit the form, it has the item number pre-written in the email that I receive.
Thats how I have it working, but cannot figure out how to get it where they have to fill out at least their name and email before the form will submit.
All you need to do is put required as an attribute on the <input ...> tag(s), and the browser will not allow the form to be submitted without something being filled in. Additionally, if you use type="email", it will validate the field and make sure it contains a valid email address. It is just part of the HTML, so it will work whether you’re using PHP or any other system.
Ya all you have to do is put that in the input. Right. That and the hundred other things you’ll have to do to get it working cross browser now that your html5. You should probably include that part too in the simple description. If you want to use js which will work for 98% of people then just copy and paste my code above. If you want to use php then I can show you a simple script for that.
I really dont care what I use, I just need it not to send without making sure they fill out Name and Email. I have tried everything I can think of and found a bunch of tutorials, It just isnt working for some reason. So Please, if you can help me with the php script, I would sure appreciate it.
Do this… Copy and paste my simple js code above into your web design program. Don’t add your stuff yet. Just get mine working. It will out of the box. Once you have it working then add your layout to one piece at a time testing throughout. If it stops working go back.