I am using confirm method of JavaScript, which executes fine in Chrome, but it is not working in Firefox. addListItem() function is not executed when I am using Firefox. (check=true) I did validation of radio buttons group. jf all buttons are checked then only want to submit form.
if(check) {
confirmOnsubmit();
} else {
alert('Please make sure all statememt are answered and remark is filled if rating of any statement given as Rarely or Never');
return false;
}
function confirmOnsubmit(){
if(confirm("Are you sure you want to submit")) {
addListItem();
return true;
} else {
alert("You selected cancel");
return false;
}
}
Related
I'm having an issue with my validation process. I'm not using a standard "submit" button, rather I have <span class="button" id="print">Print</span> and jQuery listens for a click. This is the validation code I have when that "button" is clicked:
var validation = "";
function validate() {
$("#servDetails").find("input").each(function () {
if ($(this).prop("required") && $(this).val() == "") {
validation = false;
}
else {
validation = true;
}
});
$("#checklist").find("input[required]").each(function () {
if ($(this).prop("required") && $(this).val() == "") {
validation = false;
}
else {
validation = true;
}
});
}
$("#print").on("click", function() {
validate();
if (validation == false) {
alert("Please fill out all required inputs!");
return false;
}
else {
window.print();
}
});
If I click the button without filling anything out (all items blank), I get my alert as expected.
If I fill out all of the required elements, it pulls up the print dialouge as expected.
However, if I leave some of the boxes blank while others are correctly filled, it still goes to print instead of giving me the alert like I need. Any thoughts?
The code have to be rewritten, or better replace it with any validation plug-in.
But in your case, I suppose, you just forgot to return, in case you found some not filled field. So if you have any filled input it override your validation variable.
The simplest solution is to remove
else {validation = true;} code blocks, and add
validation = true;
at the beggining of the function.
I want to check if there's at least one checkbox that checked in a form after the submit button is clicked, if no, the the user should get message and the form SHOULDN'T be submit, so I wrote this code:
jQuery(document).ready(function ($) {
$('#price_quote_create_invoice').click(function () {
$('.price-quotes-table input[type="checkbox"]').each(function () {
if ( $(this).is(':checked') ){
$('#post').submit();
return false;
} else {
alert("You didn't chose any checkbox!");
return false;
}
}) ;
});
});
However, after I press ok on the alert box, the form does submit.
Any idea why this is happening?
Your code is almost right.
You return false on a click event but what you really want to do is to stop the submit event.
Change like this.
$('#yourFormId').submit(function(){
if (!$(this).find('input[type="checkbox"]:checked').length) {
alert("You didn't chose any checkbox!");
return false;
}
});
alert('You didn't chose any checkbox!');
You have an additional comma in your alert..
You can use event.preventDefault() to do this. event is the first argument of your click function. Reference
I have found this online:
function submitButtonClick(button) {
if (typeof (Page_ClientValidate) == 'function') {
if (Page_ClientValidate() == false) {
return false;
}
}
button.style.display = 'none'; // disable won't work
return true;
}
I am not good with Javascript so I couldn't tell what to change...I have a usercontrol with a few buttons, including a submit button. And they are used on every page of my site. And on some pages I have customvalidators. So when a custom validator doesn't validate, the button is gone and there is nothing left to do. What should I change here for the things to work the way I need? Thanks
Hi basically i can't seem to get the form validation to work on my form in ie8 or below. It works absolutely fine every where else though.
Basically its along these lines:
function validateform() {
if (document.getElementById('firstinput').value == '') {
alert("Select start Date");
document.getElementById('firstinput').focus();
return false;
}
if (document.getElementById('secondinput').value == '') {
alert("Select end Date");
document.getElementById('secondinput').focus();
return false;
}
if (document.getElementById('restriction').checked == false) {
alert('Please select I have read and understand the above restrictions.');
return false;
}
if (document.getElementById('termscondition').checked == false) {
alert('Please select terms and condition..');
return false;
}
if (document.getElementById('letters_code').value == '') {
alert("Enter captcha code..");
document.getElementById('letters_code').focus();
return false;
}
return true;
}
Just wondered if there are any obvious mistakes that i can't see :s thanks for any help in advance.
Editing because i phased this terribly!
I have encountered an issue involving a submit button being named submit, that only failed in IE, and not in firefox/chrome, if you could make sure that is not the issue, that would help!
Alternatively, more information would be helpful, as there does not appear to be anything wrong with the code posted
The following code works somewhat in chrome and IE but not in Firefox.
The idea is to force users to check an "Agree" box before advancing by following either one of the possible links available.
<script type="text/javascript">
function agreeCheck()
{
valid = false;
var agree = document.getElementById('agree');
if(isAgree(agree)){
valid= true;
}
return valid;
}
function isAgree(elem)
{
if ( elem.checked == false )
{
Show_Stuff(agreespan, "true");
return false;
}
else
{
Show_Stuff(agreespan, "false");
return true;
}
}
function Show_Stuff(warning,on_off)
// Function that will swap the display/no display for
// all content within span tags
{
if ((warning.style.display == "none")&&(on_off =="true"))
{
warning.style.display = "";
}
else
{
warning.style.display = "none";
}
}
</script>
<input type="checkbox" name="agree" value="signed" id="agree">
I agree</input> <span ID="agreespan" style="display: none">
<font color="red">You must agree in order to proceed</font>
</span>
<button type="button" title="Proceedt" class="btn-proceed" onclick="if (agreeCheck()==true){ window.location='myURL'; } else{ return agreeCheck();}"></button>
<input type="image" src="anotherURL" title="myTitle" onClick="return agreeCheck();"/>
Notes:
obviously myURL and anotherURL are
actual valid URLs
clicking on the first button when the box is not checked prevents the page from progressing but does not reveal the error message in the span in Chrome and IE. In Firefox it does nothing regardless of the box status
clicking the image link (input type="image") when the box is not checked works well in Chrome and IE and the error message appears. In Firefox the link is followed regardless of the box's status.
I realize that this could be written differently to simplify things. The problem is that I am implementing this in Magento where I only have access to chunks of code separately so I can't combine the parts of the If Else statement in a separate function.
**edit: I changed the if statement (one line before last) to
if (agree.checked ==true){ ...
this fixed the issue in chrome and IE and now those browsers are behaving properly. Firefox is still not doing what I want it to do
The problem is in isAgree function. Try the following:
function isAgree(elem)
{
if (!elem.checked == "Checked")
{
Show_Stuff(agreespan, "true");
return false;
}
else
{
Show_Stuff(agreespan, "false");
return true;
}
}
Hope it solves the issue. The solution resolves around this "checked" property.
span_tag.style.display is used for layout purposes not to hide or show the span tag
It doesn't work in your case because the JavaScript is probably breaking.
Try changing everything to use the following code
warning.style.visibility = "hidden";
warning.style.visibility = "visible";