Divide data for form?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • robhalv1
    New Member
    • Aug 2010
    • 1

    Divide data for form?

    I am currently pulling a 10 digit number form a database and propulating a form.

    I have recently changed the form to 3 input boxes and can't figure out how to split the data (i.e. xxx, xxx, xxxx).

    Here is snippet from my current code:

    Code:
    function loadModalPromo()
    {
    	modalpromo = new Boxy("<?php loadPromoModalContent(); ?>", {title: "I do not have a Promo Code", modal: false, closeable: true, show: false });
    	
    	$("#mphavecontact").click(function() {
    		modalpromo.hide();
    	});
    	
    	$("#mpnotcontact").click(function() {
    		$("#mpoptionform").hide();
    		$("#mpgettingpromo").show();
    		$.ajax({
    		   type: "POST",
    		   url: "yhfiles/ajaxgetpromo.php",
    		   data: "key=" + "<?php echo $_SESSION["ajaxget_promo_key"]; ?>",
    		   success: function(msg){
    			 if(msg.length == 10)
    			 {
    				$("#logpromo").val(msg);
    			 }
    			 else
    			 {
    				 alert("Error in retrieving the promo code. Please contact the administrator.");
    			 }
    		   },
    		   complete: function(msg){
    			   $("#mpoptionform").show();
    			   $("#mpgettingpromo").hide();
    			   modalpromo.hide();
    		   }
    		 });
    		 
    		
    	});
    }
    Any help would be appreciated.
  • johny10151981
    Top Contributor
    • Jan 2010
    • 1059

    #2
    if you do it with php
    Code:
    $value="1234567890";
    $part1=substr($value,0,3);
    $part2=substr($value,3,3);
    $part2=substr($value,6,4);
    want to do with javascript
    Code:
    var value="1234567890";
    var part1=value.substr(0,3);
    var part2=value.substr(3,3);
    var part3=value.substr(6,4);

    Comment

    Working...