In defense of everyone who has posted it recently, I have trouble
finding the new post button myself sometimes. In my mind, where it is
currently located is in a navigation bar that is not specific to the
current page.
When I'm on a page and wanting to do something within that page
my eyes naturally look at everything below the line with "JQUERY
FORUM" and the search field. To me, since it is pretty static,
everything above that line is site wide functionality, not page specific.
With all that being said, I'm not sure that it can be charged
or not, but that's my $0.02.
I've got a validation that requires an ajax call, the validation is done both on the field change event and on the form submit so I've got a named function that does the validation and just call that function from both places.
The problem I've got though is that when the form is submitted there is another validation that needs to happen via ajax, this one may or may not be required based on a form value.
The validation process I'd like to follow when the form is submitted is
make sure all the required fields have an entry
if all the fields are OK do the mandatory ajax call
if the mandatory call returns an OK, then do the optional one, if required
I cant put the optional ajax in the callback of the required one since the required one is called at other times other than when the form is submitted and I'd prefer not to duplicate the required ajax code.
Here's the code I have so far:
$(document).ready(function(){
$("#nextBtn").click(function() {
isValid();
});
$("#poNumber").change(function() {
if ($("#poNumber").val() != "") {
var temp = validatePO();
}
});
});
function isValid(){
var isValid = true;
var emailReg = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
$(".isReq").removeClass("inpNeeded");
...
if ($("#contactName").val() == "") {
isValid = false;
$("#contactName").addClass("inpNeeded");
}
if ($("#phone").val() == "") {
isValid = false;
$("#phone").addClass("inpNeeded");
}
...
if (isValid) {
isValid = validatePO(); // this one needs to get called
// this is the optional one
if ($("#frfqNumber").val() != "") {
$.post("include/verifyFRFQNumber.asp",
{rfqID: $("#frfqNumber").val()},
function(data){
if (data.frfqStatus == "1") {
alert("The FRFQ number you entered does not exist.\nPlease double check the number.");
isValid = false;
}
if (isValid) {
$("#poForm").submit();
} else {
alert("Please make sure the highlighted fields have an entry.");
}
},
"json"
);
} else if (isValid) {
$("#poForm").submit();
}
} // end if isValid
}
function validatePO() {
$.get(
"include/validatePONumber.asp",
{poNumber: $("#poNumber").val()},
function(data) {
if (data.isUsed == "yes") {
alert("There is an existing purchase order on file with that PO Number.\nPlease enter a new number for this order.");
$("#poNumber").addClass("inpNeeded");
} else {
$("#poNumber").removeClass("inpNeeded");
}
}
);
}
I'm not sure if when() is the answer since the second call may or may not be needed.
I can make it work, but it would require duplicating the required ajax and then nesting the optional one in the call back, or I could make them all async false, but neither of those solutions seems quite right.
I saw this post over in the getting started forum and it reminded me of something I'd thought of a few times. That it would be helpful if there were a contact method to get in touch with a moderator. I see a lot of posts that are duplicates or that should be moved to a different forum and the only way I know to let someone know is to send them a PM and then I only send them to a couple of people that I know to be moderators.
Other forums have a moderator(s) for each forum that are listed on each forum page, or a moderator contact method somewhere that is easy to see. If this is a software limitation I guess there is nothing to be done, otherwise it might be something to look into as I think it would make things easier. I bet there are a lot of people that, not finding a way to contact someone, don't even bother.
Can anyone see why my reply in this thread: https://forum.jquery.com/topic/making-my-code-more-generic is marked as spam? Is there something in the content or did I click something in error? I don't recall having this problem before.
A nice addtion to the boards here might be a new forum for book and tutorial reviews and announcements. This would be nice in that it would give people a place to go to examine books and get real user opinions before buying them.
For more control, and to avoid getting flooded by publishers and authors, the initial post in each thread could be made by a moderator from their own or a submitted review about a specific book/tutorial and then all the discussion would follow. Another advantage would be potential revenue from people following links and buying the books.
Here is one I cannot seem to figure out. I've got a set of text boxes with the change event bound to a function that will do some validation and add some numbers together. If the user enters something that is not a valid number I want to alert them and then put the focus back on the offending field.
My problem is that the event that I'm capturing is not the actual tab key or mouse click. So even though I set the focus in my event handler, the initial event that started the whole thing still moves the focus to the next field or where ever the mouse was clicked.
I've tried preventDefault, stopPropagation, returning false, and a bunch of other things to no avail. I hope it is something I'm missing or not seeing. If not it seems like my only choice is to capture all the events (key presses, mouse clicks etc. and handle them all which seems rather tedious.
// set change events for computed form fields $('input[name^="cap"]').change(function(event){ if (testFundsFields("cap1") && testFundsFields("cap2") && testFundsFields("cap4")){ var c1 = parseInt($("#cap1").val()); var c2 = parseInt($("#cap2").val()); var c4 = parseInt($("#cap4").val());
$("#cap3").val(c1 + c2); $("#cap5").val(parseInt($("#cap3").val()) + c4); } else { /* right here is where I've tried everything to stop the focus from moving */ }// end if fields have valid values }); });
// make sure passed in field ID has a valid numeric value, set it to 0 (zero) if it is empty function testFundsFields(fieldID){ var retVal = true; var theVal = $("#" + fieldID).val(); if (theVal != "" && isNaN(theVal)) { alert("Please enter values as whole numbers."); $("#" + fieldID).focus(); $("#" + fieldID).val(""); retVal = false; } else if (theVal == "") { $("#" + fieldID).val("0"); }
return retVal; } </script> </head> </head>
<body> field 1: <input class="moneyInp" id="cap1" /> <br/> field 2: <input class="moneyInp" id="cap2" /> <br/> field 3: <input class="moneyInp" id="cap3" readonly /> (=1 + 2) <br/> field 4: <input class="moneyInp" id="cap4" /> <br/> field 5: <input class="moneyInp" id="cap5" readonly /> (=3 + 4) </body> </html>