I am validating my form using Javascript, but would like to display the errors using Jquery. Can you do this?
you can do this:
function Validate(){
if(isValidate){
// do somthing
}else{
$("#error").fadeIn(500);// here is jQuery code
}
}
Related
I have a form on my site and would like an icon to be displayed in addition to the validation message.
I can get it to display, but am having trouble getting it to display at the right moment.
I am using jQuery Validation and have set the function "onfocusout".
The problem now is that it does not execute the default code.
Is there a function how I can call this?
My jQuery / JS:
$("#form").validate({
onfocusout: function (element) {
// I want to call the Default behavior here!
if ($(!element.valid())) {
errorIcon.removeAttribute("hidden")
}
else {
errorIcon.setAttribute("hidden", "true")
}
}
}
});
Do not mind the logic in the Code.
Thanks for helping
I want to trigger a call to a function ,when any change is done in the text box to validate the input .
I don't want to add an inline call , rather want to add the code in the script block .
$(document).ready(function () {
$("#LocationName").change(validateLocationName);
});
function validateLocationName()
{
var formAddress = contractAddress.getData();
formAddress.LocationName = $("#LocationName").val();
if ( validate condition) {
--- add error or etc
return false;
}
return true;
}
attached the code i am trying to use , but the function does not get called . Any help will be appreciated
Your code, if stripped down to just call the function, works like below. Just make sure you have included the necessary jQuery script and also that you are not getting any other error. e.g if getData() is actually working and if statement has valid check like if (formAddress.LocationName == $("#LocationName").val())
<textarea id="LocationName"></textarea>
<script>
$(document).ready(function () {
$("#LocationName").change(validateLocationName);
});
function validateLocationName() {
alert($("#LocationName").val());
}
</script>
i have one simple jQuery function, that does not work. I need to write a function that if anyone click on some class called 'modal-opened' it need to add class to body 'modal-open'. So i write function like this:
$(document).ready(function(){
$(".modal-opened").click(function(){
$("body").addClass("modal-open");
});
});
I have that same function in JavaScript that works actually, here it is.
document.getElementById("modal-opened").addEventListener("click", myFunction);
function myFunction() {
$("body").addClass("modal-open");
}
I need that same but in jQuery.
Notice you get modal-opened by ID in plain JS:
// You get modal-opened by ID in plain JS
$(document).ready(function(){
$("#modal-opened").click(function(){
$("body").addClass("modal-open");
});
});
try to do this:
<script>
$(document).on('click','.modal-opened',function(){
$("body").addClass("modal-open");
});
</script>
There is an error in your jQuery code with reference to working javascript code you shared.
document.getElementById("modal-opened") in javascript is equivalent to $("#modal-opened") and not $(".modal-opened").
In jQuery, you can access an element by Id using # and by class using dot.
Hope this helps..
Please share your feedback.
I have 4 forms on 1 page, one for each package. Can I use the form's onclick to establish a var and use it in the jquery function? The jquery function is included in a js file assigned to the the page. Just want to access the var in the jquery function for a specific form to be submitted.
<form action="javascript:" method="POST" id="buy-form_2"
onclick="javascript:$thisform='buy-form_2';" >
var thisformtext = "#"+$thisform;
$(document).ready(function()
{
$(thisformtext).submit(function(event)
{
i may or may not be close but this one escapes me...
Very curious
Edit: ended up using:
$('form').submit(function(event){
window.buyform = '#'+"buy-form_"+$(this).attr('id').slice(-1);//alert(buyform);
.......
}
I know window.var is overloaded but beats 4 X 12 jquery functions
Thanks for the help!
W
if you only want to differentiate form, you can have id check.
$(document).ready(function(){
$('form').submit(function(event){
if($(this).attr('id') == 'buy-form_2'){
............
}
});
});
I want to create a custom confirm box like this
var should_I_move_forward = myconfirmbox();
myconfirmbox will show a popup with Yes/No button, I want to pause the execution here until user hit yes or no, how can I achieve it?
i.e. same functionality as of js confirm method buy my own UI.
You can't.
You will have to move the logic that follows the confirmation inside the myconfirmbox method, or pass it as parameters (to call on demand)..
something like
function ConfirmYes(){
// do something for Yes
}
function ConfirmNo(){
// do something for No
}
function myconfirmbox(yesCallback, noCallback){
// whatever you currently do and at the end
if (confirmation == 'yes'){
yesCallback();
} else {
noCallback();
}
}
myconfirmbox(ConfirmYes, ConfirmNo);
What I did is not elegant at all but it working fine for me! I create a custom confirm function like:
function jqConf(msg,y,n){
$('body').append('<div id="confirmBox">msg</div>');
$('#confirmBox').append('<div id="confirmButtons"></div>');
$('#confirmButtons').append('<button onclick="'+y+'();">Yes</button>');
$('#confirmButtons').append('<button onclick="'+n+'();">No</button>');
}
function defaultYes(){
alert('Awesomeness!');
}
function defaultNo(){
alert('No action taken!');
}
The I use it like this:
<button onclick="jqConf('Do you love me?','defaultYes','defaultNo')">Confirm</button>
This way I pass as a string the name of the function to run if Yes and if No individually and is executed by the user event.
As I say, nothing elegant but it works!, no loops or confusing codes, I think?, In the example I'm using jQuery but can be accomplish with plain JavaScript too!