Checkbox Validation For Terms And Service
Dec 15, 2006
I'm working on a Ruby on Rails web app and I'm trying to add a quick and dirty client-side Javascript validation, to ensure that users click a checkbox agreeing to our Ts and Cs, before clicking the "Register" button submits their info.
I'll post the generated HTML, rather than the Rails stuff.
This is the button that shouldn't submit the form until the checkbox has been clicked:
<input name="commit" onClick="return check_agreed()" type="submit" value="Complete Registration" /> or <a href="/">Cancel</a>
First off, to confirm that the onClick actually checks check_agreed(), I kept check_agreed() simple, just popping up an alert then returning false.
<script language="JavaScript">
function check_agreed()
{
alert("check_agreed checked");
return false;
}
</script>
This seems to work fine - the alert pops up and nothing is submitted. I have a checkbox:
<input type="checkbox" name="terms_agreed">
I'd like this to be checked before the form can be submitted, so I've altered check_agreed() and added some debugging alerts.
function check_agreed()
{
alert("in check_agreed");
if(terms_agreed == checked)
{
alert("checked");
return true;
}
alert("Please agree to the Terms and Conditions");
return false;
}
So now the first alert, "in check_agreed" pops up, but then the form is submitted, with neither "checked" nor "Please agree..." popping up. This happens regardless of whether the checkbox has been clicked.
I'm sure I'm doing something wrong - it seems to be to do with referring to the checkbox. Should I be giving the checkbox's complete path, rather than referring to it by its name? I've tried to work out the correct path according to the DOM, but it still does the same thing.
View 4 Replies
ADVERTISEMENT
Dec 5, 2009
I'm trying to write a simple javascript and am having some difficulties. The purpose of the script is to send an xml document to the service. The response is not important.
I'm getting this error: "HTTP Is Not Defined"
Code:
View 4 Replies
View Related
Jun 19, 2009
I have a form and trying to validate all fields with jquery validation plugin.Every thing is fine except the checkboxes which i create dynamically.[code]how i make a rule which check that if no check box is checked then show error message like above input fileds do.
View 1 Replies
View Related
Jan 2, 2005
I have been working over this Javascript a few times and cannot seem to get it working correctly, I have found the javascript mostly by searching on the net and on this forum.
What I am trying to do is to use a function with in another function to check that a group of checkboxes have atleast one checked. Code:
View 4 Replies
View Related
Feb 20, 2006
I am displaying some datas in listbox and checkbox which are gathered from the database. without choosing any of the checkbox and listbox if the user clicks the button i need to display an alert message. pls help. i am sending the code in which i am trying now.
LISTBOX
<select name="adminroles" >
<option value="" selected>--Select--</option>
<?
$admin_roles = mysql_query ("select * from role_master");
$admin_roles= mysql_num_rows($admin_roles);
for($k=0;$k<$admin_roles;$k++)
{
?>
<option value= "<? echo mysql_result($admin_roles,$k,role_id); ?>">
<? echo mysql_result($admin_roles,$k,role_name);?> </option>
<?
}
?>
</select>
<input type="checkbox" value="<? echo mysql_result($res1,$z,function_id);?>" name="chk[]" <? if($edit_func_id == mysql_result($res1,$z,function_id)){?>
checked<? } ?> >
View 1 Replies
View Related
May 3, 2006
I have a form liek this:
<form method="post" action="somefile.php">
<input type='checkbox' name='boxes[]' value='abc'> abc<br>
<input type='checkbox' name='boxes[]' value='def'> def<br>
<input type='checkbox' name='boxes[]' value='ghi'> ghi<br>
<input type="submit" value="Continue to Step 2..." name="s2"></p>
</form>
I want to make sure that people cannot continue without checking at least 1 checkbox. The name of the checkboxes will be same.
View 1 Replies
View Related
Jun 1, 2011
I have a text input, "Pets" and a checkbox "noPetsHS"."Pets" is required except when "noPetsHS" is checked. My validation rule currently is - and does not work? Pets:{required: "#noPetsHS:checked=false", min:1}"Pets" is usually required, very few select the checkbox, but I don't want "Pets" required if they do.I can find no reference to Rules and testing for absence of check and then requiring the text input.
View 3 Replies
View Related
Sep 25, 2009
I have a form, on which I have multiple checkboxes and text fields.Now I want that the form can't submit untill at least 1 checkbox is selected or a text field is filled.But even with the javascript validation I already have the form still submits.Any help on this one?Here is the whole page on which the checkboxes, text fields and javascript validation are:PHP Code:
<script type="text/javascript" language="javascript">
function checkCheckBoxes() {
if (document.form2.nbs_vmb[].checked == false)
[code]....
View 2 Replies
View Related
May 6, 2009
I have a form with a password the user must enter. The password has no conditions, but there is a checkbox next to it. Users have an option to choose one of two checkboxes. If they choose the checkbox with the password then the password is required, the other checkbox does not require a password so the form would not need to validate the password in that instance.
View 2 Replies
View Related
Sep 18, 2011
I have a simple html form with 2 text fields and submit button 1 user name pwd/tokenand 1 checkbox 'First time user'if 'first time user' is selected then the 'Submit' button to be enabled only if the customer puts exactly 6 digits on pwd/token. if it's unchecked then the submit button to be enabled only if the customer enters 10 digits(pin_token code)
View 6 Replies
View Related
Dec 11, 2007
how I can make sure that out of a group of 10 checkboxes atleast 1 is checked?
View 2 Replies
View Related
Sep 19, 2006
<form name="new_page" action="test.php"><input type="checkbox" name="allowed[]" value="2">
<input type="checkbox" name="allowed[]" value="2">
<input type="checkbox" name="allowed[]" value="2">
<input class="button_140" type="button" value="Toevoegen"
if (!document.new_page.allowed[].checked){ popupalert('allowed'); }
else { this.form.submit(); }"></form>
This is a piece of the code I've written. It's supposed to check if one of the allowed[]-checkboxes is checked, and if not, to run function popupalert('allowed');. It's not working. Can someone tell me how to fix this?
View 1 Replies
View Related
Apr 20, 2007
I have a form which contains a number of check boxes in format of fielduse_x where x is incremented each time (1 - 30)
Everytime one of the checkboxes is ticked or unticked i want to perform a function for related boxes but i am having difficaulty doing this.
The code i have in the javascript is :
function changeStatus(f)
{
alert(f);
if(document.newForm.fielduse_[f].checked==true)
alert("YES")
else
alert("NO");
}
f is passed from the form field and contains the number (1 - 30). I know that the form is passing the values across as alert(f) gives the correct number. I don't seem to be able to get the next line to work. How do i put the value of f into the if statment as what i have done isn't working
if(document.newForm.fielduse_[f].checked==true)
View 5 Replies
View Related
Nov 1, 2007
I have a simple form which I'm trying to validate. I have around 8 checkboxes that the user has to agree with, and if they dont, they get the message saying "you did not accept the training princples, yada yada".
I also have a few text fields asking for their details.
Maybe I'm missing something simple here, but everytime I submit the form, it doesnt validate. Im not fantastic at coding, but I was hoping this would be quite straight forward. All I'm trying to do is get a message up if the user doesnt agree with all of the checkboxes. Code:
View 6 Replies
View Related
May 9, 2009
I found something here, but I'm not good at javascript, and i don't know which part of the code is the right! I need only for Checkboxes!
[url]
I need something like: onclick="check_if_at_least_one_is_selected()"
There is only one <form></form> and all checkboxes are same type...
View 9 Replies
View Related
Jul 24, 2005
I have a number of checkboxes and radio buttons in an HTML form that are named as arrays, ie.
<INPUT type="checkbox" ID="i1" VALUE="MILK" NAME="Q1[]">
<INPUT type="checkbox" ID="i2" VALUE="SUGAR" NAME="Q1[]">
<INPUT type="checkbox" ID="i3" VALUE="BISCUIT" NAME="Q1[]">
I need to keep the 'NAME' as an array as above because of the form processing that is used after submit.
I was really hoping to use Javascript to validate the form and make sure that each checkbox group has at least one option selected , but my javascript messes up because the 'NAME' is Q1[] as opposed to Q1. I had been using:
<script>
function validate() {
if (!(mainform.Q1[0].checked || mainform.Q1[1].checked|| mainform.Q1[2].checked)) {
alert('Please answer question 1.');
event.returnValue=false;
}}
</script>
but this only works when I name the checkboxes NAME="Q1". Is anyone aware of how to get the validate function to work (or another way of validating the form) even when the checkboxes and radio buttons are named like NAME="Q1[]".
View 2 Replies
View Related
Jan 10, 2011
I have an HTML table with <tr> sections that is generated by php which looks like the following
HTML Code:
<tr align='center' class='row_a'>
<td align='center'><input id = 'assign0' type='checkbox' name='agent_8949' value='0' /></td></tr>
<tr align='center' class='row_b'>
<td align='center'><input id = 'assign1' type='checkbox' name='agent_8950' value='1' /></td></tr>
<tr align='center' class='row_a'>
<td align='center'><input id = 'assign2' type='checkbox' name='agent_8951' value='2' /></td></tr>
<tr align='center' class='row_b'>
<td align='center'><input id = 'assign3' type='checkbox' name='agent_8952' value='3' /></td></tr>
The id's and values are generated by php, my problem is, I want to use javascript to check if anyone of the check boxes has been checked on submission meaning that I have to go through the <tr> list. Here is my JS code which only works for one id.
Code:
//I know the length of the checkbox (checkBoxID) fields which is the number of rows in the database table
function validate(checkBoxID){
var ids_Prefix = 'assign';//we know all the ids starts with this string
for (var i = 0; i < checkBoxID; ++i) {
if(document.getElementById(id_Prefix+i).checked == false){//how do I check the next one?
alert("You did not make any selection");
return false;
}}}
View 3 Replies
View Related
Jun 18, 2009
I have a form and trying to validate all fields with jquery validation plugin.Every thing is fine except the checkboxes which i create dynamically.[code] how i make a rule which check that if no check box is checked then show error message like above input fileds do
View 1 Replies
View Related
Jul 20, 2005
I have an FAQ page on my site, but, because much of the information could be
relative to the area council's bylaws, I want to have a pop-up window appear
when someone clicks the "FAQ's" menu button. In the window will be my
disclaimer regarding the use of the information on the FAQ's page, and then
I want them to click either "I agree" (action will close pop-up and direct
them to FAQ's page) or "I disagree" (action will close pop-up and leave them
at page they were at when clicking the link).
The script needs to be linked to the clicking of an image.
View 7 Replies
View Related
Aug 31, 2007
Is there anyway to use Javascript (or other code) so that if you've arrived at a web page on your site via google (and there is alot of text on the screen) the javascript will scroll automatically to the searched terms?Is there anyway to use Javascript (or other code) so that if you've arrived at a web page on your site via google (and there is alot of text on the screen) the javascript will scroll automatically to the searched terms?
View 1 Replies
View Related
Sep 5, 2011
when the visitor wants to register on my site, they have to fill in there email address in the requiered field and then check the terms box to activate the register button...thats all good, but there seems to be a bit of a bug......it seems that when they fill in the email address and press return, it skips passed the terms box and goes straight to the register page...
[Code]...
View 2 Replies
View Related
Mar 4, 2011
I am trying to remove a validation message from the screen when a user checks a checkbox. I do require that the user enter a last name in a text box before they click the submit button. If they dont, the validation message appears. I am trying to hide or clear that validation message when they select a check box on the page. The HTML for it is below but am wondering if you canremove the messagein JQuery.[code]...
View 3 Replies
View Related
May 2, 2009
Trying to use jquery to validate that a minimum of 7 check boxes are selected.
The code is as follows:
It works if i set the (checked == 0) and then at least 1 is selected... but when i run it as is... it won't submit even if more than 7 are selected... Is my code wrong? is the variable checked not an integer?
View 2 Replies
View Related
May 24, 2010
I have to highlight the search terms in the text area.
I have one text Filed,search Button and text area.
Quote ... After i have enter the search string in the text field whenever i click the search button it highlight the search terms which is available in the text area and focus the search term in text area.
I have try to do this by using jquery. But in mozilla,I can't get the focus to the search term at the time of search.
I have to scroll down the text area for find the focused search term.
In I.E. also it doesn't work properly. Otherwise if any post related to highlight search term in text area is also appreciable.
View 1 Replies
View Related
Jun 14, 2010
I have a fairly straightforward form with validation on a number of fields, all of which is working fine.
I have credit card information fields being validated only if a Payment Method radio button is set to 'Visa' or 'Mastercard', and this is also working correctly.
<input name="payment_method" value="visa" type="radio" class="radio payment_method">Visa
<input name="payment_method" value="mastercard" type="radio" class="radio payment_method">Mastercard
[Code].....
These input names don't appear anywhere else in the HTML document and they're not validated fields, however if either of them are checked, the conditional credit card validation no longer fires, although the remaining non-conditional validation on the page continues to work as normal.
EDIT: It would appear that if *any* of the radio buttons on the form are selected, the payment information validation is disabled.
I'm at a loss as to explain what's happening. I'm leaning towardsinput[#payment_method]:checked syntax, and specifically the :checked syntax as potentially causing the issue
View 1 Replies
View Related
Nov 3, 2011
On my homepage (index.html), I have a search field which fires the users input (text) parameters off to another website to perform the search (ie. results.html). What I'm now trying to do is create an iframe on index.html which shows the search results on the same page (without the user having to visit the other website. Does anyone know if this is possible using javascript?
The reason behind this is so that we can use the search on our old website on our new one... without having to re-invent the wheel.
View 6 Replies
View Related