Nested jquery "if else if" crashes - javascript

I have this block of javascript which is working just fine.
$('#<%=Button_PayFees.ClientID%>').click(function (evt) {
var valuefirstname = $('#<%=TextBox_FirstName.ClientID%>').val().toUpperCase();
var valuelastname = $('#<%=TextBox_LastName.ClientID%>').val().toUpperCase();
var valueaddress = $('#<%=TextBox_Address.ClientID%>').val().toUpperCase();
var valuecity = $('#<%=TextBox_City.ClientID%>').val().toUpperCase();
var valuestate = $('#<%=Dropdownlist_States.ClientID%>').val().toUpperCase();
var valuezipcode = $('#<%=TextBox_ZipCode.ClientID%>').val().toUpperCase();
var valuephone = $('#<%=TextBox_Phone.ClientID%>').val().toUpperCase();
var valueEmail = $('#<%=TextBox_EmailAddress.ClientID%>').val().toUpperCase();
var valuecreditcard = $('#<%=DropDownList_CreditCard.ClientID%>').val();
var valuecreditcardnumber = $('#<%=TextBox_CreditCard.ClientID%>').val().toUpperCase();
var valuecsvcode = $('#<%=TextBox_CSVCode.ClientID%>').val().toUpperCase();
var valueparticipantfirstname = $('#<%=TextBox_ParticipantFirstName.ClientID%>').val().toUpperCase();
var valueparticipantlastname = $('#<%=TextBox_ParticipantLastName.ClientID%>').val().toUpperCase();
var valueTeamName = $("#<%=DropDownList_CheerLevel.ClientID%>").find("option:selected").text();
var valueOrganization = $('#<%=TextBox_Organization.ClientID%>').val().toUpperCase();
var valuedeliveryfirstname = $('#<%=TextBox_DeliveryFirstName.ClientID%>').val().toUpperCase();
var valuedeliverylastname = $('#<%=TextBox_DeliveryLastName.ClientID%>').val().toUpperCase();
var valuedeliveryaddress = $('#<%=TextBox_DeliveryAddress.ClientID%>').val().toUpperCase();
var valuedeliverycity = $('#<%=TextBox_DeliveryCity.ClientID%>').val().toUpperCase();
var valuedeliverystate = $('#<%=DropDownList_DeliveryStates.ClientID%>').val().toUpperCase();
var valuedeliveryzipcode = $('#<%=TextBox_DeliveryZipCode.ClientID%>').val().toUpperCase();
if(valueparticipantfirstname == '' ){
alert('Participant firstname is required.');
evt.preventDefault();
$('#<%=TextBox_ParticipantFirstName.ClientID%>').focus();
}
else if (valueparticipantlastname == ''){
alert('Participant lastname is required.');
evt.preventDefault();
$('#<%=TextBox_ParticipantLastName.ClientID%>').focus();
}
else if (valueOrganization == '') {
alert('Organization is required.');
evt.preventDefault();
$('#<%=TextBox_Organization.ClientID%>').focus();
}
else if (valueTeamName == 'Select Cheer Level') {
alert('Select Cheer Level from the drop down list.');
evt.preventDefault();
$('#<%=DropDownList_CheerLevel.ClientID%>').focus();
}
else if (selection == 'Select DVD Option') {
alert('Please select a DVD option from the drop down list.');
evt.preventDefault();
$('#<%=DropDownList_Options.ClientID%>').focus();
}
else if (valuefirstname == '') {
alert('Firstname is required.');
evt.preventDefault();
$('#<%=TextBox_FirstName.ClientID%>').focus();
}
else if (valuelastname == ''){
alert('Lastname is required.');
evt.preventDefault();
$('#<%=TextBox_LastName.ClientID%>').focus();
}
else if(valueaddress == '') {
alert('Address is required.');
evt.preventDefault();
$('#<%=TextBox_Address.ClientID%>').focus();
}
else if(valuecity == '') {
alert('City is required.');
evt.preventDefault();
$('#<%=TextBox_City.ClientID%>').focus();
}
else if(valuestate == 'SELECT STATE') {
alert('Select state from the drop down list.');
evt.preventDefault();
$('#<%=DropDownList_States.ClientID%>').focus();
}
else if(valuezipcode == '') {
alert('Zip code is required.');
evt.preventDefault();
$('#<%=TextBox_ZipCode.ClientID%>').focus();
}
else if(valuephone == '') {
alert('Phone is required.');
evt.preventDefault();
$('#<%=TextBox_Phone.ClientID%>').focus();
}
else if(valueEmail == '') {
alert('Email Address is required.');
evt.preventDefault();
$('#<%=TextBox_EmailAddress.ClientID%>').focus();
}
else if(valuecreditcard == 'SELECT CARD TYPE') {
alert('Select credit card type from the drop down list.');
evt.preventDefault();
$('#<%=DropDownList_CreditCard.ClientID%>').focus();
}
else if(valuecreditcardnumber == '') {
alert('Enter credit card number.');
evt.preventDefault();
$('#<%=TextBox_CreditCard.ClientID%>').focus();
}
else if(valuecsvcode == '') {
alert('Enter credit card ID code.');
$('#<%=TextBox_CSVCode.ClientID%>').focus();
evt.preventDefault();
}
});
When I change it to add checks for delivery information when a checkbox is checked it crashes ... no idea why as I'm not getting any feed back from the site. The code that crashes is (note the nested else if):
$('#<%=Button_PayFees.ClientID%>').click(function (evt) {
var valuefirstname = $('#<%=TextBox_FirstName.ClientID%>').val().toUpperCase();
var valuelastname = $('#<%=TextBox_LastName.ClientID%>').val().toUpperCase();
var valueaddress = $('#<%=TextBox_Address.ClientID%>').val().toUpperCase();
var valuecity = $('#<%=TextBox_City.ClientID%>').val().toUpperCase();
var valuestate = $('#<%=Dropdownlist_States.ClientID%>').val().toUpperCase();
var valuezipcode = $('#<%=TextBox_ZipCode.ClientID%>').val().toUpperCase();
var valuephone = $('#<%=TextBox_Phone.ClientID%>').val().toUpperCase();
var valueEmail = $('#<%=TextBox_EmailAddress.ClientID%>').val().toUpperCase();
var valuecreditcard = $('#<%=DropDownList_CreditCard.ClientID%>').val();
var valuecreditcardnumber = $('#<%=TextBox_CreditCard.ClientID%>').val().toUpperCase();
var valuecsvcode = $('#<%=TextBox_CSVCode.ClientID%>').val().toUpperCase();
var valueparticipantfirstname = $('#<%=TextBox_ParticipantFirstName.ClientID%>').val().toUpperCase();
var valueparticipantlastname = $('#<%=TextBox_ParticipantLastName.ClientID%>').val().toUpperCase();
var valueTeamName = $("#<%=DropDownList_CheerLevel.ClientID%>").find("option:selected").text();
var valueOrganization = $('#<%=TextBox_Organization.ClientID%>').val().toUpperCase();
var valuedeliveryfirstname = $('#<%=TextBox_DeliveryFirstName.ClientID%>').val().toUpperCase();
var valuedeliverylastname = $('#<%=TextBox_DeliveryLastName.ClientID%>').val().toUpperCase();
var valuedeliveryaddress = $('#<%=TextBox_DeliveryAddress.ClientID%>').val().toUpperCase();
var valuedeliverycity = $('#<%=TextBox_DeliveryCity.ClientID%>').val().toUpperCase();
var valuedeliverystate = $('#<%=DropDownList_DeliveryStates.ClientID%>').val().toUpperCase();
var valuedeliveryzipcode = $('#<%=TextBox_DeliveryZipCode.ClientID%>').val().toUpperCase();
if(valueparticipantfirstname == '' ){
alert('Participant firstname is required.');
evt.preventDefault();
$('#<%=TextBox_ParticipantFirstName.ClientID%>').focus();
}
else if (valueparticipantlastname == ''){
alert('Participant lastname is required.');
evt.preventDefault();
$('#<%=TextBox_ParticipantLastName.ClientID%>').focus();
}
else if (valueOrganization == '') {
alert('Organization is required.');
evt.preventDefault();
$('#<%=TextBox_Organization.ClientID%>').focus();
}
else if (valueTeamName == 'Select Cheer Level') {
alert('Select Cheer Level from the drop down list.');
evt.preventDefault();
$('#<%=DropDownList_CheerLevel.ClientID%>').focus();
}
else if (selection == 'Select DVD Option') {
alert('Please select a DVD option from the drop down list.');
evt.preventDefault();
$('#<%=DropDownList_Options.ClientID%>').focus();
}
else if (valuefirstname == '') {
alert('Firstname is required.');
evt.preventDefault();
$('#<%=TextBox_FirstName.ClientID%>').focus();
}
else if (valuelastname == ''){
alert('Lastname is required.');
evt.preventDefault();
$('#<%=TextBox_LastName.ClientID%>').focus();
}
else if(valueaddress == '') {
alert('Address is required.');
evt.preventDefault();
$('#<%=TextBox_Address.ClientID%>').focus();
}
else if(valuecity == '') {
alert('City is required.');
evt.preventDefault();
$('#<%=TextBox_City.ClientID%>').focus();
}
else if(valuestate == 'SELECT STATE') {
alert('Select state from the drop down list.');
evt.preventDefault();
$('#<%=DropDownList_States.ClientID%>').focus();
}
else if(valuezipcode == '') {
alert('Zip code is required.');
evt.preventDefault();
$('#<%=TextBox_ZipCode.ClientID%>').focus();
}
else if(valuephone == '') {
alert('Phone is required.');
evt.preventDefault();
$('#<%=TextBox_Phone.ClientID%>').focus();
}
else if(valueEmail == '') {
alert('Email Address is required.');
evt.preventDefault();
$('#<%=TextBox_EmailAddress.ClientID%>').focus();
}
else if($('#<%= Checkbox_Delivery.ClientID %>').is(':checked')) {
else if (valuedeliveryfirstname == '') {
alert('Please enter the first name of the person the DVD is being delivered to.');
evt.preventDefault();
$('#<%=TextBox_DeliveryFirstName.ClientID%>').focus();
}
else if (valuedeliverylastname == '') {
alert('Please enter the last name of the person the DVD is being delivered to.');
evt.preventDefault();
$('#<%=TextBox_DeliveryLastName.ClientID%>').focus();
}
else if (valuedeliveryaddress == '') {
alert('Please enter the delivery Address.');
evt.preventDefault();
$('#<%=TextBox_DeliveryAddress.ClientID%>').focus();
}
else if (valuedeliverycity == '') {
alert('Please enter the delivery city.');
evt.preventDefault();
$('#<%=TextBox_DeliveryCity.ClientID%>').focus();
}
else if (valuedeliverystate == 'SELECT STATE') {
alert('Select the delivery state from the drop down list.');
evt.preventDefault();
$('#<%=DropDownList_DeliveryStates.ClientID%>').focus();
}
else if (valuedeliveryzipcode == '') {
alert('Please enter the delivery Zip code.');
evt.preventDefault();
$('#<%=TextBox_DeliveryZipCode.ClientID%>').focus();
}
}
else if(valuecreditcard == 'SELECT CARD TYPE') {
alert('Select credit card type from the drop down list.');
evt.preventDefault();
$('#<%=DropDownList_CreditCard.ClientID%>').focus();
}
else if(valuecreditcardnumber == '') {
alert('Enter credit card number.');
evt.preventDefault();
$('#<%=TextBox_CreditCard.ClientID%>').focus();
}
else if(valuecsvcode == '') {
alert('Enter credit card ID code.');
$('#<%=TextBox_CSVCode.ClientID%>').focus();
evt.preventDefault();
}
});
something in the nested else if causes the code to crash. I can't see it.

This doesn't look right!
else if($('#<%= Checkbox_Delivery.ClientID %>').is(':checked')) {
else if (valuedeliveryfirstname == '') {
The indented else if should just be if there is no preceeding if inside the block.
else if($('#<%= Checkbox_Delivery.ClientID %>').is(':checked')) {
if (valuedeliveryfirstname == '') {

First of all, you should not be using else if for all the other fields otherwise the if loop will exit when it enters the first matching condition. It should be:
if(valueparticipantfirstname == '' ){
alert('Participant firstname is required.');
evt.preventDefault();
$('#<%=TextBox_ParticipantFirstName.ClientID%>').focus();
}
if (valueparticipantlastname == ''){
alert('Participant lastname is required.');
evt.preventDefault();
$('#<%=TextBox_ParticipantLastName.ClientID%>').focus();
}
if (valueOrganization == '') {
alert('Organization is required.');
evt.preventDefault();
$('#<%=TextBox_Organization.ClientID%>').focus();
}
if (valueTeamName == 'Select Cheer Level') {
alert('Select Cheer Level from the drop down list.');
evt.preventDefault();
$('#<%=DropDownList_CheerLevel.ClientID%>').focus();
}
.
.
.
Also, this code:
else if($('#<%= Checkbox_Delivery.ClientID %>').is(':checked')) {
else if (valuedeliveryfirstname == '') {
needs to be changed to:
else if($('#<%= Checkbox_Delivery.ClientID %>').is(':checked')) {
if (valuedeliveryfirstname == '') {
.
.
.

Related

Unknown error the true part of if state dosen't work

I've write a code for simple pass and username form that will show up a content if u entered the user and password correct
but it seems like there is a logical error on it that I can't find
function show() {
if (document.getElementById("user").value == "ahmed" && document.getElementById("pass").value == "ahmed") {
document.getElementById("content").style.visibility = "visible";
document.getElementById("pass1").style.visibility = "hidden";
} else if (document.getElementById("user").value != "ahmed" && document.getElementById("pass").value != "ahmed") {
alert("Password and username is incorrect")
} else if (document.getElementById("pass").value != "ahmed") {
alert("Password is incorrect");
} else if (document.getElementById("user").value != "ahmed") {
alert("Username is incorrect")
}
}
The function work when I entered a wrong pass or username but when I entered them right nothing oth this code , the page just refresh automatically
document.getElementById("content").style.visibility = "visible";
document.getElementById("pass1").style.visibility = "hidden";
source
I created a fiddle and it is working fine
I don't know why it is not working for you. look at the fiddle
https://jsbin.com/vezito/edit?html,js,output
function show() {
var content = document.getElementById("content");
var name = document.getElementById("name");
var pass = document.getElementById("pass");
if (name.value == "ahmed" && pass.value == "ahmed") {
document.getElementById("content").style.visibility = "visible";
document.getElementById("pass").style.visibility = "hidden";
} else if (name.value != "ahmed" && pass.value != "ahmed") {
alert("Password and username is incorrect");
} else if (pass.value != "ahmed") {
alert("Password is incorrect");
} else if (name.value != "ahmed") {
alert("Username is incorrect");
}
}

OnClick doesn't work after Jquery validations

I have given validations through jquery which works fine on button click.
But as soon as I fill all the data into the page, my onClick does not fires. I dont know why. Please suggest.
Here is my jquery code:-
var ErrArr = [];
$(document).ready(function () {
$('#btnSave').click(function (e) {
e.preventDefault();
validateTitle();
validateddl();
validateTextBoxes();
if (ErrArr.length > 0) {
alert(ErrArr.join("\n"));
ErrArr = [];
return false;
}
});
function validateTitle() {
if ($("#ddlTitle").val() > "0") {
if ($("#ddlTitle").val() == "1104" && $("#txtTitle").val() === "") {
ErrArr.push("Please enter the text in other title");
}
} else {
ErrArr.push('Please select the title');
}
}
function validateTextBoxes() {
if ($("#txt_emp_fname").val() === "") {
ErrArr.push('First name is required');
}
if ($("#txt_emp_mname").val() === "") {
ErrArr.push('Middle name is required');
}
if ($("#txt_emp_lname").val() === "") {
ErrArr.push('Last name is required');
}
if ($("#txtDateofJoin").val() === "") {
ErrArr.push('Date of joining is required');
}
if ($("#txtReligion").val() === "") {
ErrArr.push('Religion is required');
}
if ($("#txtBloodGroup").val() === "") {
ErrArr.push('Blood group is required');
}
if ($("#txtPersonalEmail").val() === "") {
ErrArr.push('Email Id is required');
}
if ($("#txtDtOfBirth").val() === "") {
ErrArr.push('Date of birth is required');
}
if ($("#txtAt").val() === "") {
ErrArr.push('Place of birth is required');
}
if ($("#txtTaluka").val() === "") {
ErrArr.push('Taluka is required');
}
if ($("#txtPostOffice").val() === "") {
ErrArr.push('Post office is required');
}
if ($("#txtDistrict").val() === "") {
ErrArr.push('District is required');
}
if ($("#txtStatePersonal").val() === "") {
ErrArr.push('State is required');
}
if ($("#txtDtMarriage").val() === "") {
ErrArr.push('Date of Marriage is required');
}
if ($("#TxtPassportNo").val() === "") {
ErrArr.push('Passport no is required');
}
if ($("#txtIdMark").val() === "") {
ErrArr.push('Identification mark is required');
}
}
function validateddl() {
if ($("#ddlGender").val === "" || $("#ddlGender").val() == "0") {
ErrArr.push('Please select the gender');
}
if ($("#ddlMaritalStatus").val === "" || $("#ddlMaritalStatus").val() == "0") {
ErrArr.push('Please select the Marital Status');
}
if ($("#ddlNationality").val === "" || $("#ddlNationality").val() == "0") {
ErrArr.push('Please select the Nationality');
}
}
});
Also see my aspx of button:-
<asp:Button ID="btnSave" CssClass="button" Text="Save" runat="server"
CausesValidation="true" onclick="btnSave_Click"
/>
I suggest you do NOT use the click of the button but the submit of the form to validate:
$(document).ready(function () {
$('#formID').on("submit",function (e) {
// e.preventDefault(); // does not belong here
validateTitle();
validateddl();
validateTextBoxes();
if (ErrArr.length > 0) {
e.preventDefault();// but here
alert(ErrArr.join("\n"));
ErrArr = [];
}
});
.
.
.
I assume that also means you should make your button a submit button and make sure the asp does not add a click event since it is already assigned by the jQuery
$('#btnSave').on("click", function(e) {
//e.preventDefault();
validateTitle();
validateddl();
validateTextBoxes();
if(ErrArr.length > 0) {
e.preventDefault(); //use e.preventDefault here
alert(ErrArr.join("\n"));
ErrArr = [];
//return false;
}
});
move event prevent on the button click handler only when client validation fails.
$('#btnSave').click(function (e) {
validateTitle();
validateddl();
validateTextBoxes();
if (ErrArr.length > 0) {
alert(ErrArr.join("\n"));
ErrArr = [];
e.preventDefault();
return false;
}
});
Try this
$('#btnSave').click(function(e) {
//e.preventDefault();
validateTitle();
validateddl();
validateTextBoxes();
if(ErrArr.length > 0) {
e.preventDefault(); //use e.preventDefault here
alert(ErrArr.join("\n"));
ErrArr = [];
//return false;
}
});

Jquery form validation coding

My Jquery validation is not working, below is the script coding. I am getting a
Fatal error: Uncaught exception
error and not sure why. I know one of the reasons can be the validation code isnt correct. Is the coding correct or is there errors?
<script type="text/javascript">
$('form#contact').submit(function(e) {
var isValidZip = /(^\d{5}$)|(^\d{5}-\d{4}$)/.test(jQuery('#form_zip').val());
var isValidYear = /^\d{4}$/.test(jQuery('#gradDate').val());
var year_number = parseInt(jQuery('#gradDate').val());
var isValidEmail = /^(([^<>()[\]\\.,;:\s#\"]+(\.[^<>()[\]\\.,;:\s#\"]+)*)|(\".+\"))#((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/.test(jQuery('#form_email').val());
var first_name = jQuery.trim(jQuery('#first_name').val());
var last_name = jQuery.trim(jQuery('#last_name').val());
var form_email = jQuery.trim(jQuery('#form_email').val());
var street = jQuery.trim(jQuery('#street').val());
var city = jQuery.trim(jQuery('#city').val());
var state = jQuery.trim(jQuery('#state').val());
var isValidPhone = /^[2-9]\d{2}[2-9]\d{2}\d{4}$/.test(jQuery('#phone_day').val());
function validZip(zip)
{
if (zip.match(/^[0-9]{5}$/)) {
return true;
}
zip=zip.toUpperCase();
if (zip.match(/^[A-Z][0-9][A-Z][0-9][A-Z][0-9]$/)) {
return true;
}
if (zip.match(/^[A-Z][0-9][A-Z].[0-9][A-Z][0-9]$/)) {
return true;
}
return false;
}
if(!validZip(jQuery('#form_zip').val())){
alert('Please enter a valid Zip Code.');
}
else if(!isValidYear || (year_number > <?php echo date('Y')?>)){
alert('Please enter a valid High School Graduation Year.');
}
else if(!isValidEmail (jQuery('#form_email').val())){
alert('Please enter a valid Email Address.');
}
else if(first_name.length <= 0 || first_name == 'First Name' || (!first_name.match(/[a-zA-Z]/)) || (first_name.match(/[0-9]/))){
alert('Please enter your First Name.');
}
else if(last_name.length <= 0 || last_name == 'Last Name' || (!last_name.match(/[a-zA-Z]/)) || (last_name.match(/[0-9]/))){
alert('Please enter your Last Name.');
}
else if(street.length <= 0 || street == 'Street Address'){
alert('Please enter your Street Address.');
}
else if(city.length <= 0 || city == 'City'){
alert('Please enter your City.');
}
else if(state.length <= 0 || state == 'State'){
alert('Please enter your State by 2 letter abbreviation.');
}
else if(country.length <= 0 || country == 'Other'){
alert('Please enter your Country.');
}
else if(!isValidPhone){
alert('If your phone number is correct, close this box and then Click the button in the form.');
}
else {
$('form#mainform').submit();
}
return false;
}
return false;
}
});
</script>
You have php inside your JavaScript code:
else if(!isValidYear || (year_number > <?php echo date('Y')?>)){

Conditional valdiation of required fields

I have a page where the user enters their address. I want to make city, state and zip code required fields, but here's the catch. Either the user is required to enter both the city and the state OR they are required to enter the zip code. How do I do this javascript?
For now I have
function Form(f) {
for (var n = 0; n < f.elements.length; n++) {
if ((f.elements[n].name).indexOf("zip_code") > -1) {
var zipcode = f.elements[n].value;
if (zipcode.length == "") {
if ((f.elements[n].name).indexOf("cityname") > -1) {
var city = f.elements[n].value;
if (city.length == "") {
alert("Enter City name");
break;
}
}
if ((f.elements[n].name).indexOf("statename") > -1) {
var state = f.elements[n].value;
if (state.length == "") {
alert("Enter State name");
break;
}
}
} else {
//return true; then do something
return false;
}
} else if (zipcode.length == "") {
alert("Enter zipcode");
break;
return false;
}
}
}
Can you please try this?
function Form(f) {
var cityname = document.getElementsByName('cityname')[0].value;
var statename = document.getElementsByName('statename')[0].value;
var zip_code = document.getElementsByName('zip_code')[0].value;
if( (cityname.length==0 && statename.length==0 ) ){
if(zip_code.length==0){
alert("Enter zipcode");
return false;
}
return true;
}else if( (cityname.length==0 || statename.length==0 ) ){
if (cityname.length == 0) {
alert("Enter City name");
return false;
}else if (statename.length == 0) {
alert("Enter State name");
return false;
}
return true;
}
}
Something like this should help
if( zipcode.length){
/* validate zipcode*/
}else{
if( city.length && state.length){
}else{
/* must have city and state*/
}
}
use a variable flag.
flag = 0;
if city and state
make flag as 1
if zip
make flag as 1
if flag==0 then validation failed
else allow to submit form

Javascript Focus Is Not Working on Aspx Page

Hy Guys,
Please Look at the code and Try to Help Out. The function ive written is not working but its RUNNING properly. Its about To set focus on next content on page im using it on an ASPX page. Heres my code Below :
function SetFocusOnSave(CTag,NTag)
{
alert('Running'+CTag+NTag);
var CurrentTag=document.getElementById(CTag);
var NextTag = document.getElementById(NTag);
if ( (event.keyCode==13)||(event.keyCode==9) )
{
if(CurrentTag.value=="")
{
alert("Please Enter Detail First");
CurrentTag.focus();
}
if(CurrentTag.value!="")
{
event.returnValue=true;
document.getElementById(NextTag).focus();
}
}
}
snametxt.Attributes.Add("onkeypress",
SetFocusOnSave('<%=snametxt.ClientID%>','<%=sdesctxt.ClientID%>');");
have you tried to replace
document.getElementById(NextTag).focus();
with
NextTag.focus();
?
You have to add return false; after you found the false in validation otherwise the flow will continue till end.
Try this function:
function SetFocusOnSave(CTag, NTag) {
alert('Running' + CTag + NTag);
var CurrentTag = document.getElementById(CTag);
var NextTag = document.getElementById(NTag);
if ((event.keyCode == 13) || (event.keyCode == 9))
{
if (CurrentTag.value == "")
{
alert("Please Enter Detail First");
CurrentTag.focus();
return false;
}
if (CurrentTag.value != "") {
event.returnValue = true;
NextTag.focus();
return false;
}
}
};
Hy Guys Ive Tried A NEW CODE AND Fortunately Its Working Fine Here its my Code
function Navigation(CTag, NTag, Number) {
var CurrentTag = document.getElementById(CTag);
var NextTag = document.getElementById(NTag);
var IsNumber = Number; //Checking if value is number
if (NextTag.disabled == true) {
NextTag.disabled = false;
NextTag.className = "txt";
}
if (event.keyCode == 9) {
CurrentTag.focus();
event.returnvalue = false;
}
if (event.keyCode != 9) {
if (event.keyCode == 13) {
if (IsNumber == "Y") {
if (NextTag.disabled == true) {
NextTag.disabled = false;
}
if (CurrentTag.value != "") {
NextTag.focus();
event.returnvalue = true;
}
if (CurrentTag.value == "") {
alert('Please Enter Value To Proceed Further.');
CurrentTag.focus();
event.returnvalue = false;
}
if (isNaN(CurrentTag.value)) {
alert("Please Enter A Valid Number");
CurrentTag.value = "";
CurrentTag.focus();
}
}
if (IsNumber == "N") {
if (CurrentTag.value == "") {
alert('Please Enter Value To Proceed Further.');
CurrentTag.focus();
event.returnvalue = false;
}
if (CurrentTag.value != "") {
NextTag.focus();
event.returnvalue = true;
}
}
}
}
};
Thanks ya'll !! :)

Categories

Resources