jQuery(document).ready(function($) { /*================================ = SMS form = ================================*/ // Get status paramater var status = getUrlVars()["Status"]; // Show succes or fail status if (status == "200") { $("#reussi").show(); $("#formSMS").css("display","none"); }else if (status == "0") { $("#echou").show(); } // limit texte area input characters $("textarea[maxlength]").bind('input propertychange', function() { var maxLength = $(this).attr('maxlength'); if ($(this).val().length > maxLength) { $(this).val($(this).val().substring(0, maxLength)); } }); // Add content of the inputs in a single input $("#formSMS").keyup(function(event) { var nom = $("input[name='nom']").val(); var telephone = $("input[name='telephone']").val(); var message = $("textarea[name='message_area']").val(); var complete_message = "Message du Site web - " + "Nom: " + nom + " Téléphone: " + telephone + " Message: " + message; $(".constructor").val(complete_message); $("input[name='message']").val(complete_message); }); // validate form before sending $("#formSMS").submit(function(e) { // e.preventDefault(); phone=validatePhone(); name=validateName(); if (phone && name) { $("#formSMS").submit(); }else{ return false; } }); // Get Url parameters function getUrlVars(){ var vars = [], hash; var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&'); for(var i = 0; i < hashes.length; i++) { hash = hashes[i].split('='); vars.push(hash[0]); vars[hash[0]] = hash[1]; } return vars; } // Validate phone number function validatePhone() { phone = $("#formSMS input[name='telephone']").val(); phone = phone.replace(/[^0-9]/g, ''); if(phone.length != 10) { // Error $("#formSMS input[name='telephone']").css('border', '1px solid #990000'); $(".error_phone").show(); return false; } else { // Succes $("#formSMS input[name='telephone']").css('border', 'solid 1px #ccc'); $(".error_phone").hide(); return true; } } // Validate name function validateName() { name = $("#formSMS input[name='nom']").val(); if(isNaN(name) && name != "") { // Succes $("#formSMS input[name='nom']").css('border', 'solid 1px #ccc'); $(".error_name").hide(); return true; } else { // Error $("#formSMS input[name='nom']").css('border', '1px solid #990000'); $(".error_name").css('display', 'block'); return false; } } /*----- End of SMS form ------*/ });