Adding a i agree radio button or checkbox. Seemingly Impossible
I am at the verlast point of an assignment of modifying a system and i need to add a "iagree" style checkbox. The system already will not submit the form if fields are blank, however i need it to not submit i.e pop up a warning. when a I agree checkbox or radio button is not selected. I have tried a million things so if anyone can figure it out you will be my god.
The following is my javascript which checks blank fields etc and displays a warning. I need to add a check radio button of name "agree" to it.
<div class="internal_booking_form">
<script type="text/JavaScript">
<!--
The function directly below code calculates the value of a series of checkboxes and radio buttons i already have. Im not sure if it matters that i have some already but i thought i'd include a note.
$(document).ready(function() {
function recalculate() {
var sum = 0;
var base = 0;
$("input[type=checkbox]:checked").e开发者_如何学Goach(function() {
sum += parseInt($(this).attr("rel"));
});
sum += parseInt($(":radio[name='duration']:checked").attr("rel"), 10); // or some attribute that has the price
$("#output").html(sum);
}
$("input[type=checkbox], :radio[name='duration']").change(function() {
recalculate();
});
});
This is the rest of the code, where i assume it would be best to place a checkcheckbox function
function newPopup(url) {
popupWindow = window.open(
url,'popUpWindow','height=700,width=800,left=10,top=10,resizable=yes,scrollbars=yes,toolbar=yes,menubar=no,location=no,directories=no,status=yes')
}
function checkForm() {
var err=0;
var msg2="";
<?php
$reqFields=array(
"name",
"phone",
"email",
"comments",
"suburb",
"postcode",
"captcha"
);
foreach ($reqFields as $v) { ?>
if (document.getElementById('<?php echo $v?>').value==0 || document.getElementById('<?php echo $v?>').value=="00") {
if (err==0) {
document.getElementById('<?php echo $v?>').focus();
}
document.getElementById('<?php echo $v?>').style.backgroundColor='#ffa5a5';
err=1;
}<?php
}
?>
var reg1 = /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/; // not valid
var reg2 = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/; // valid
if (document.getElementById('email').value==0 || !reg2.test(document.getElementById('email').value)) {
if (err==0) {
document.getElementById('email').focus();
}
document.getElementById('email').style.backgroundColor='#ffa5a5';
err=1;
}
if (err==0) {
return true;
} else {
alert("Please complete all highlited fields to continue.");
return false;
}
}
function checkFieldBack(fieldObj) {
if (fieldObj.value!=0) {
fieldObj.style.backgroundColor='#EAEAEA';
}
}
function checkNumeric(value){
var anum=/(^\d+$)|(^\d+\.\d+$)/
if (anum.test(value))
return true;
return false;
}
function noAlpha(obj){
reg = /[^0-9.,]/g;
obj.value = obj.value.replace(reg,"");
}
//-->
</script>
<form name="ff1" enctype="multipart/form-data" method="post" action="booking.event.processing.php" onsubmit="return checkForm();">
I assume your "iagree" checkbox has the id iagree. If you insert
if( !$('input#iagree').is(":checked") ) {
err = 1;
}
if (err==0) {
...
this should work. You may add an additional messagebox if you want an explicit information for agreeing to something.
精彩评论