Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Nov 2013
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Need help understanding this JavaScript

    I have some JavaScript written by someone else and I'm trying to figure our exactly where some values are coming from, how they are formatted and what is being done with them. The values in question are citNumFirst, dateFirst, cdValues and cnValues.

    This JavaScript is used to recursively open form fields for numbers and dates, then make an Ajax request (I think), but the Ajax data doesn't make any sense (value is: data: "countCitNum=" + countCitNum,)

    Here is the code I need help with. Again, I'm trying to figure out where these values citNumFirst, dateFirst, cdValues and cnValues are coming from as these are what are being sent through the form submission (according to Fiddler).

    Code:
     $(document).ready(function() {
    
    	 
    
    /******
    
     Select Date of citation issue with JQuery datepicker 
    
    ******/
    
    	 $(function() {
    
    	$(".date").datepicker();
    
    //    $( "#datepicker" ).datepicker('setDate', new Date());
    
      });
    
      	$("#dateFirst").val('');
    
    	$("#dateFirst").attr("disabled",true);
    
    	$("#citNumFirst").val('');
    
    		 		
    
     });
    
      
    
    var citArray = [];  
    
    var thisCount = 1;
    
    var countCitNum = -1;
    
    var cnArray = [];  
    
    var citNum = '';
    
    var cnFirst = '';
    
    var cdArray = [];
    
    var issueDate = '';
    
    
    
    $("#cnValues").val(cnArray);
    
    $("#cdValues").val(cdArray);
    
    
    
    
    
    /*******
    
    Add dynamically created Citation Number text fields using an hmtl link
    
    ******/
    
    
    
      function addCitNumber(){
    
    	 var citNumField = document.getElementById("citNumFirst");
    
    	  if(citNumField.value ==''){
    
    		  var addfield_msg = "<span style='color:#F00;'>Please enter <br />Citation Number</span>";
    
    		   $('#addfield_error').removeClass('hideCat');
    
    		  $('#addfield_error').append(addfield_msg);
    
    		  return false;
    
    	  }else{
    
    	 countCitNum++;
    
    	 var addHTML = '';
    
    	 var addDateHTML = ''
    
    	 $.ajax({
    
    			 type: "POST",
    
    					 url: "/ci/ajaxCustom/addCitNum",
    
    					 data: "countCitNum=" + countCitNum,
    
    					 success: function(results){
    
    						 if(results){
    
    							countCitNum = results;							
    
    						 }						 
    
    						addHTML = '<div id="newCitNum_'+countCitNum+'"><br /><strong>Citation Number:</strong><br /><input type="text" id="citNumInput_'+countCitNum+'" onchange="setCitNum(this,'+countCitNum+')"/></div>';
    
    						addDateHTML = '<div id="newDate_'+countCitNum+'"><br /><strong>Citation Issue Date:</strong><br /><input type="text" id="citDateInput_'+countCitNum+'" class="date" onchange="setIssueDate(this,'+countCitNum+')" readonly="readonly"/><a href="javascript:void(0)" onclick="subtractCitNumber('+countCitNum+');"><img src="/euf/assets/themes/standard/images/delete_x.gif" width="29" height="23" border="0" class="imgDelete"/>Delete Citation Number</a></div>';
    
    						 $('#anotherCitNum').append(addHTML);
    
    						 $('#anotherCitDate').append(addDateHTML);
    
    						  document.getElementById("#citDateInput_"+countCitNum);
    
    	 					  $("#citDateInput_"+countCitNum).attr("disabled",true);
    
    						 $(".date").datepicker();
    
    					 }
    
    	 });
    
    	}
    
    	 data="";
    
      }
    
    /*******
    
    Delete dynamically created Citation Number text fields using an hmtl link
    
    ******/  
    
       function subtractCitNumber(countCitNum){
    
    		cnArray[countCitNum] = '';
    
    		cdArray[countCitNum] = '';
    
    		$('#newCitNum_'+countCitNum).empty();
    
    	 	$('#newCitNum_'+countCitNum).addClass('hide');
    
    		$("#cnValues").val(cnArray); 
    
    		$('#newDate_'+countCitNum).empty();
    
    		$('#newDate_'+countCitNum).addClass('hide'); 	
    
    		$("#cdValues").val(cdArray);
    
       }
    
    /*  
    
    *//******
    
     Set Additional Citation Numbers and enable the date input
    
    ******/  
    
    function setCitNum(obj, countCitNum){		
    
    		if(obj.value !='')
    
    		{
    
    			cnArray[countCitNum] = obj.value;
    
    			$("#cnValues").val(cnArray);	
    
    			$("#citDateInput_"+countCitNum).removeAttr("disabled");
    
    		}else{
    
    			$('#citDateInput_'+countCitNum).val('');	
    
    			$("#citDateInput_"+countCitNum).attr("disabled", true);	
    
    		}
    
    }
    
    
    
    /******
    
     Set Issue Date of additonal citations  
    
    ******/
    
      function setIssueDate(obj, countCitNum){
    
    	if(obj.value !=''){
    
    	cdArray[countCitNum] = obj.value; 
    
      	}else{
    
    	cdArray[countCitNum] = ''; 
    
    	}
    
    	$("#cdValues").val(cdArray);
    
    }
    
    /******
    
     Set Citation Number and enable date input unless Citation Number is blank
    
    ******/ 
    
    function setFirstNum(obj){	
    
    	cnFirst = obj.value;	
    
    	$('#addLink').empty();
    
    	if(obj.value !='')
    
    		{
    
    			$("#citNumFirst").val(cnFirst);
    
    			$("#dateFirst").removeAttr("disabled");
    
    			$('#addfield_error').empty();
    
    			$('#addfield_error').addClass('hideCat');
    
    			var addLinkHTML = "<a href='javascript:void(0)' onclick='addCitNumber();'>Click here to add another Citation Number</a>"
    
    			$('#addLink').append(addLinkHTML);
    
    		}else{
    
    			$('#dateFirst').val('');	
    
    			$("#dateFirst").attr("disabled", true);	
    
    		}
    
    }
    
    /******
    
     Set Issue Date of citation 
    
    ******/
    
      function setFirstDate(obj){	
    
    			var issueDate = obj.value;
    
    			$("#dateFirst").val(issueDate);		
    
    }
    
      </script>
    
      
           <input type="hidden" name="cnValues" id="cnValues" />
    
          <input type="hidden" name="cdValues" id="cdValues" />

  • #2
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,284
    Thanks
    23
    Thanked 611 Times in 610 Posts
    Could you please either post a link to the site this is on or post the HTML code that goes along with it. Thank you.
    Evolution - The non-random survival of random variants.

    "If you leave hydrogen alone, for long enough, it begins to think about itself."


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •