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:
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.
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 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.
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:
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.
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.
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)
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.
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)
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?
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
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:
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[]".
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; }}}
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
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.
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?
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...
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]...
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?
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.
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.
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
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.