如何使用创建动态表单来转换单词中的金额

时间:2018-01-04 05:13:01

标签: javascript jquery

从这里,我正在做文本框,假设我正在输入100,在它下面将显示一百,它工作正常,现在我点击add Sharing button,同一行再次,我在这里创建,在这里我想实现我的功能,如果我输入100它应该显示一百,但这里我的功能不起作用,我不怎么办任何人都意味着,请更新我的代码段

var i=0;
$(document).on("click",".addSharingType",function() {
  i++;
	
  var htmlText = '';
  htmlText += '<div class="controls"><div class="row"><div class="col-md-6 col-sm-4 col-xs-12"> <label>Sharing Type</label><select class="form-control seelectcss1 border" name="sharingType[]" required=""><option value="">Select</option><option value="Single Sharing">Single Sharing</option><option value="Two Sharing">Two Sharing</option><option value="Three Sharing">Three Sharing</option><option value="Four Sharing">Four Sharing</option></select></div></div><div class="row entry"><div class="col-md-3 col-sm-4 col-xs-12" style="padding-right:5px;"><div class="form-group" id="imm"><label class="control-label">Rent With Food :</label><br><input type="number" class="form-control nput border" name="withFood[]" id="withfood" onkeyup="word.innerHTML=convertNumberToWords(this.value)"> <img src="image/rup.png" id="try"> <div id="word"></div><p class="custom-error amountError" style="display:none">Please Enter Amount</p></div></div><div class="col-md-3 col-sm-4 col-xs-12" style="padding-right:5px;"><div class="form-group" id="imm"><label class="control-label">Rent Without Food </label><br><input type="number" class="form-control nput border" name="withoutFood[]" id="withoutfood" onkeyup="word1.innerHTML=convertNumberToWords1(this.value)">	<img src="image/rup.png" id="try"><div id="word1"></div></div></div><div class="col-md-3 col-sm-4 col-xs-12"><div class="form-group" id="imm"><label class="control-label">Advance Amount</label><br><input type="number" class="form-control  nput border" name="advance[]" id="advance" onkeyup="word2.innerHTML=convertNumberToWords1(this.value)"><img src="image/rup.png" id="try"><div id="word2"></div></div></div>';
   
  htmlText +='<div class="col-md-3 col-sm-4 col-xs-12"><div class="form-group" id="imm"><button type="button" class="btn btn-success addSharingType" style="margin-top: 26px;height: 38px;" id="admore"><span class="glyphicon glyphicon-plus"></span> Add</button>&nbsp;&nbsp;<button type="button" class="btn btn-danger removeSharingType" style="margin-top: 26px;height: 38px;" id="admore"><span class="glyphicon glyphicon-minus"></span> remove</button></div></div>';
   
  htmlText +='</div></div>';
  htmlText +='</div><br>';
  $('.sharingType').append(htmlText);
});

$(document).on("click",".removeSharingType",function() {
  $(this).closest('.controls').remove();
});
</script>
<script>
function convertNumberToWords(amount) {
    var words = new Array();
    words[0] = '';
    words[1] = 'One';
    words[2] = 'Two';
    words[3] = 'Three';
    words[4] = 'Four';
    words[5] = 'Five';
    words[6] = 'Six';
    words[7] = 'Seven';
    words[8] = 'Eight';
    words[9] = 'Nine';
    words[10] = 'Ten';
    words[11] = 'Eleven';
    words[12] = 'Twelve';
    words[13] = 'Thirteen';
    words[14] = 'Fourteen';
    words[15] = 'Fifteen';
    words[16] = 'Sixteen';
    words[17] = 'Seventeen';
    words[18] = 'Eighteen';
    words[19] = 'Nineteen';
    words[20] = 'Twenty';
    words[30] = 'Thirty';
    words[40] = 'Forty';
    words[50] = 'Fifty';
    words[60] = 'Sixty';
    words[70] = 'Seventy';
    words[80] = 'Eighty';
    words[90] = 'Ninety';
    amount = amount.toString();
    var atemp = amount.split(".");
    var number = atemp[0].split(",").join("");
    var n_length = number.length;
    var words_string = "";
    if (n_length <= 9) {
        var n_array = new Array(0, 0, 0, 0, 0, 0, 0, 0, 0);
        var received_n_array = new Array();
        for (var i = 0; i < n_length; i++) {
            received_n_array[i] = number.substr(i, 1);
        }
        for (var i = 9 - n_length, j = 0; i < 9; i++, j++) {
            n_array[i] = received_n_array[j];
        }
        for (var i = 0, j = 1; i < 9; i++, j++) {
            if (i == 0 || i == 2 || i == 4 || i == 7) {
                if (n_array[i] == 1) {
                    n_array[j] = 10 + parseInt(n_array[j]);
                    n_array[i] = 0;
                }
            }
        }
        value = "";
        for (var i = 0; i < 9; i++) {
            if (i == 0 || i == 2 || i == 4 || i == 7) {
                value = n_array[i] * 10;
            } else {
                value = n_array[i];
            }
            if (value != 0) {
                words_string += words[value] + " ";
            }
            if ((i == 1 && value != 0) || (i == 0 && value != 0 && n_array[i + 1] == 0)) {
                words_string += "Crores ";
            }
            if ((i == 3 && value != 0) || (i == 2 && value != 0 && n_array[i + 1] == 0)) {
                words_string += "Lakhs ";
            }
            if ((i == 5 && value != 0) || (i == 4 && value != 0 && n_array[i + 1] == 0)) {
                words_string += "Thousand ";
            }
            if (i == 6 && value != 0 && (n_array[i + 1] != 0 && n_array[i + 2] != 0)) {
                words_string += "Hundred and ";
            } else if (i == 6 && value != 0) {
                words_string += "Hundred ";
            }
        }
        words_string = words_string.split("  ").join(" ");
    }
    return words_string;
}

function convertNumberToWords1(amount) {
    var words = new Array();
    words[0] = '';
    words[1] = 'One';
    words[2] = 'Two';
    words[3] = 'Three';
    words[4] = 'Four';
    words[5] = 'Five';
    words[6] = 'Six';
    words[7] = 'Seven';
    words[8] = 'Eight';
    words[9] = 'Nine';
    words[10] = 'Ten';
    words[11] = 'Eleven';
    words[12] = 'Twelve';
    words[13] = 'Thirteen';
    words[14] = 'Fourteen';
    words[15] = 'Fifteen';
    words[16] = 'Sixteen';
    words[17] = 'Seventeen';
    words[18] = 'Eighteen';
    words[19] = 'Nineteen';
    words[20] = 'Twenty';
    words[30] = 'Thirty';
    words[40] = 'Forty';
    words[50] = 'Fifty';
    words[60] = 'Sixty';
    words[70] = 'Seventy';
    words[80] = 'Eighty';
    words[90] = 'Ninety';
    amount = amount.toString();
    var atemp = amount.split(".");
    var number = atemp[0].split(",").join("");
    var n_length = number.length;
    var words_string = "";
    if (n_length <= 9) {
        var n_array = new Array(0, 0, 0, 0, 0, 0, 0, 0, 0);
        var received_n_array = new Array();
        for (var i = 0; i < n_length; i++) {
            received_n_array[i] = number.substr(i, 1);
        }
        for (var i = 9 - n_length, j = 0; i < 9; i++, j++) {
            n_array[i] = received_n_array[j];
        }
        for (var i = 0, j = 1; i < 9; i++, j++) {
            if (i == 0 || i == 2 || i == 4 || i == 7) {
                if (n_array[i] == 1) {
                    n_array[j] = 10 + parseInt(n_array[j]);
                    n_array[i] = 0;
                }
            }
        }
        value = "";
        for (var i = 0; i < 9; i++) {
            if (i == 0 || i == 2 || i == 4 || i == 7) {
                value = n_array[i] * 10;
            } else {
                value = n_array[i];
            }
            if (value != 0) {
                words_string += words[value] + " ";
            }
            if ((i == 1 && value != 0) || (i == 0 && value != 0 && n_array[i + 1] == 0)) {
                words_string += "Crores ";
            }
            if ((i == 3 && value != 0) || (i == 2 && value != 0 && n_array[i + 1] == 0)) {
                words_string += "Lakhs ";
            }
            if ((i == 5 && value != 0) || (i == 4 && value != 0 && n_array[i + 1] == 0)) {
                words_string += "Thousand ";
            }
            if (i == 6 && value != 0 && (n_array[i + 1] != 0 && n_array[i + 2] != 0)) {
                words_string += "Hundred and ";
            } else if (i == 6 && value != 0) {
                words_string += "Hundred ";
            }
        }
        words_string = words_string.split("  ").join(" ");
    }
    return words_string;
}
function convertNumberToWords2(amount) {
    var words = new Array();
    words[0] = '';
    words[1] = 'One';
    words[2] = 'Two';
    words[3] = 'Three';
    words[4] = 'Four';
    words[5] = 'Five';
    words[6] = 'Six';
    words[7] = 'Seven';
    words[8] = 'Eight';
    words[9] = 'Nine';
    words[10] = 'Ten';
    words[11] = 'Eleven';
    words[12] = 'Twelve';
    words[13] = 'Thirteen';
    words[14] = 'Fourteen';
    words[15] = 'Fifteen';
    words[16] = 'Sixteen';
    words[17] = 'Seventeen';
    words[18] = 'Eighteen';
    words[19] = 'Nineteen';
    words[20] = 'Twenty';
    words[30] = 'Thirty';
    words[40] = 'Forty';
    words[50] = 'Fifty';
    words[60] = 'Sixty';
    words[70] = 'Seventy';
    words[80] = 'Eighty';
    words[90] = 'Ninety';
    amount = amount.toString();
    var atemp = amount.split(".");
    var number = atemp[0].split(",").join("");
    var n_length = number.length;
    var words_string = "";
    if (n_length <= 9) {
        var n_array = new Array(0, 0, 0, 0, 0, 0, 0, 0, 0);
        var received_n_array = new Array();
        for (var i = 0; i < n_length; i++) {
            received_n_array[i] = number.substr(i, 1);
        }
        for (var i = 9 - n_length, j = 0; i < 9; i++, j++) {
            n_array[i] = received_n_array[j];
        }
        for (var i = 0, j = 1; i < 9; i++, j++) {
            if (i == 0 || i == 2 || i == 4 || i == 7) {
                if (n_array[i] == 1) {
                    n_array[j] = 10 + parseInt(n_array[j]);
                    n_array[i] = 0;
                }
            }
        }
        value = "";
        for (var i = 0; i < 9; i++) {
            if (i == 0 || i == 2 || i == 4 || i == 7) {
                value = n_array[i] * 10;
            } else {
                value = n_array[i];
            }
            if (value != 0) {
                words_string += words[value] + " ";
            }
            if ((i == 1 && value != 0) || (i == 0 && value != 0 && n_array[i + 1] == 0)) {
                words_string += "Crores ";
            }
            if ((i == 3 && value != 0) || (i == 2 && value != 0 && n_array[i + 1] == 0)) {
                words_string += "Lakhs ";
            }
            if ((i == 5 && value != 0) || (i == 4 && value != 0 && n_array[i + 1] == 0)) {
                words_string += "Thousand ";
            }
            if (i == 6 && value != 0 && (n_array[i + 1] != 0 && n_array[i + 2] != 0)) {
                words_string += "Hundred and ";
            } else if (i == 6 && value != 0) {
                words_string += "Hundred ";
            }
        }
        words_string = words_string.split("  ").join(" ");
    }
    return words_string;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css" integrity="sha384-PsH8R72JQ3SOdhVi3uxftmaW6Vc51MKb0q5P2rRUpPvrszuE4W1povHYgTpBfshb" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.3/umd/popper.min.js" integrity="sha384-vFJXuSJphROIrBnz7yo7oB41mKfc8JzQZiCq4NCceLEaO4IHwicKwpJf9c9IpFgh" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/js/bootstrap.min.js" integrity="sha384-alpBpkh1PFOepccYVYDB4do5UnbKysX5WZXm3XxPqe5iKTfUKjNkCk9SaVuEZflJ" crossorigin="anonymous"></script>

<div class="controls">
  <div class="row">			   
    <div class="col-md-6 col-sm-4 col-xs-12"> 
      <label>Sharing Type</label>
      <select class="form-control seelectcss1 border" name="sharingType[]" required="">
        <option value="">Select</option>
        <option value="Single Sharing">Single Sharing</option>
        <option value="Two Sharing">Two Sharing</option>
        <option value="Three Sharing">Three Sharing</option>
        <option value="Four Sharing">Four Sharing</option>
      </select>				   
    </div>
  </div>
						
  <div class="row entry">
    <div class="col-md-3 col-sm-4 col-xs-12" style="padding-right:5px;">
      <div class="form-group" id="imm">
        <label class="control-label">Rent With Food :</label>
        <br>
        <input type="number" class="form-control nput border" name="withFood[]" id="withfood" onkeyup="word.innerHTML=convertNumberToWords(this.value)"> 
        <div id="word"></div>					
        <p class="custom-error amountError" style="display:none">Please Enter Amount</p>		
     </div>
    </div>
		
    <div class="col-md-3 col-sm-4 col-xs-12" style="padding-right:5px;">
      <div class="form-group" id="imm">
        <label class="control-label">Rent Without Food </label>
        <br>
        <input type="number" class="form-control nput border" name="withoutFood[]" id="withoutfood" onkeyup="word1.innerHTML=convertNumberToWords1(this.value)">	
       <div id="word1"></div>
      </div>
    </div>				
    <div class="col-md-3 col-sm-4 col-xs-12">
      <div class="form-group" id="imm">
        <label class="control-label">Advance Amount</label>
        <br>
        <input type="number" class="form-control  nput border" name="advance[]" id="advance" onkeyup="word2.innerHTML=convertNumberToWords1(this.value)">
       <div id="word2"></div>					
      </div>
    </div>
    
    <div class="col-md-3 col-sm-4 col-xs-12">
      <div class="form-group" id="imm">
        <button type="button" class="btn btn-success addSharingType" style="margin-top: 26px;height: 38px;" id="admore"><span class="glyphicon glyphicon-plus"></span> Add Sharing</button>
      </div>
    </div>
  </div>
</div>
<div class="sharingType"></div>

1 个答案:

答案 0 :(得分:0)

点击&#34;添加分享&#34;时发生了ID冲突。其他节点开始具有相同的ID,word和word1。例如,在部分

<div id="word"></div><p class="custom-error amountError" style="display:none">Please Enter Amount</p></div>

因此,当你进行诸如word.innerHTML之类的调用时,它将无法工作,因为word成为集合而不是html节点。当然,我不会建议循环遍历该集合并为每个条目设置innterHTML;这不是一个好习惯。

您需要选择不同的ID。我对其他内容(someOtherWord)进行了一些小改动,以便向您显示添加新共享后,标签在此之后仍会发生变化。

我强烈建议您避免附加html字符串,而是使用appendChild。这需要一些努力,但最终,调试,维护和添加新功能将更容易。

&#13;
&#13;
var count = 0;
var i=0;
$(document).on("click",".addSharingType",function() {
  i++;
count++;
  var htmlText = '';
  htmlText += '<div class="controls"><div class="row"><div class="col-md-6 col-sm-4 col-xs-12"> <label>Sharing Type</label><select class="form-control seelectcss1 border" name="sharingType[]" required=""><option value="">Select</option><option value="Single Sharing">Single Sharing</option><option value="Two Sharing">Two Sharing</option><option value="Three Sharing">Three Sharing</option><option value="Four Sharing">Four Sharing</option></select></div></div><div class="row entry"><div class="col-md-3 col-sm-4 col-xs-12" style="padding-right:5px;"><div class="form-group" id="imm"><label class="control-label">Rent With Food :</label><br><input type="number" class="form-control nput border" name="withFood[]" id="withfood" onkeyup="word_'+count+'.innerHTML=convertNumberToWords(this.value)"> <img src="image/rup.png" id="try"> <div id="word_'+count+'"></div><p class="custom-error amountError" style="display:none">Please Enter Amount</p></div></div><div class="col-md-3 col-sm-4 col-xs-12" style="padding-right:5px;"><div class="form-group" id="imm"><label class="control-label">Rent Without Food </label><br><input type="number" class="form-control nput border" name="withoutFood[]" id="withoutfood" onkeyup="word1.innerHTML=convertNumberToWords1(this.value)">	<img src="image/rup.png" id="try"><div id="word1"></div></div></div><div class="col-md-3 col-sm-4 col-xs-12"><div class="form-group" id="imm"><label class="control-label">Advance Amount</label><br><input type="number" class="form-control  nput border" name="advance[]" id="advance" onkeyup="word2.innerHTML=convertNumberToWords1(this.value)"><img src="image/rup.png" id="try"><div id="word2"></div></div></div>';
   
  htmlText +='<div class="col-md-3 col-sm-4 col-xs-12"><div class="form-group" id="imm"><button type="button" class="btn btn-success addSharingType" style="margin-top: 26px;height: 38px;" id="admore"><span class="glyphicon glyphicon-plus"></span> Add</button>&nbsp;&nbsp;<button type="button" class="btn btn-danger removeSharingType" style="margin-top: 26px;height: 38px;" id="admore"><span class="glyphicon glyphicon-minus"></span> remove</button></div></div>';
   
  htmlText +='</div></div>';
  htmlText +='</div><br>';
  $('.sharingType').append(htmlText);
});

$(document).on("click",".removeSharingType",function() {
  $(this).closest('.controls').remove();
});
</script>
<script>
function convertNumberToWords(amount) {
    var words = new Array();
    words[0] = '';
    words[1] = 'One';
    words[2] = 'Two';
    words[3] = 'Three';
    words[4] = 'Four';
    words[5] = 'Five';
    words[6] = 'Six';
    words[7] = 'Seven';
    words[8] = 'Eight';
    words[9] = 'Nine';
    words[10] = 'Ten';
    words[11] = 'Eleven';
    words[12] = 'Twelve';
    words[13] = 'Thirteen';
    words[14] = 'Fourteen';
    words[15] = 'Fifteen';
    words[16] = 'Sixteen';
    words[17] = 'Seventeen';
    words[18] = 'Eighteen';
    words[19] = 'Nineteen';
    words[20] = 'Twenty';
    words[30] = 'Thirty';
    words[40] = 'Forty';
    words[50] = 'Fifty';
    words[60] = 'Sixty';
    words[70] = 'Seventy';
    words[80] = 'Eighty';
    words[90] = 'Ninety';
    amount = amount.toString();
    var atemp = amount.split(".");
    var number = atemp[0].split(",").join("");
    var n_length = number.length;
    var words_string = "";
    if (n_length <= 9) {
        var n_array = new Array(0, 0, 0, 0, 0, 0, 0, 0, 0);
        var received_n_array = new Array();
        for (var i = 0; i < n_length; i++) {
            received_n_array[i] = number.substr(i, 1);
        }
        for (var i = 9 - n_length, j = 0; i < 9; i++, j++) {
            n_array[i] = received_n_array[j];
        }
        for (var i = 0, j = 1; i < 9; i++, j++) {
            if (i == 0 || i == 2 || i == 4 || i == 7) {
                if (n_array[i] == 1) {
                    n_array[j] = 10 + parseInt(n_array[j]);
                    n_array[i] = 0;
                }
            }
        }
        value = "";
        for (var i = 0; i < 9; i++) {
            if (i == 0 || i == 2 || i == 4 || i == 7) {
                value = n_array[i] * 10;
            } else {
                value = n_array[i];
            }
            if (value != 0) {
                words_string += words[value] + " ";
            }
            if ((i == 1 && value != 0) || (i == 0 && value != 0 && n_array[i + 1] == 0)) {
                words_string += "Crores ";
            }
            if ((i == 3 && value != 0) || (i == 2 && value != 0 && n_array[i + 1] == 0)) {
                words_string += "Lakhs ";
            }
            if ((i == 5 && value != 0) || (i == 4 && value != 0 && n_array[i + 1] == 0)) {
                words_string += "Thousand ";
            }
            if (i == 6 && value != 0 && (n_array[i + 1] != 0 && n_array[i + 2] != 0)) {
                words_string += "Hundred and ";
            } else if (i == 6 && value != 0) {
                words_string += "Hundred ";
            }
        }
        words_string = words_string.split("  ").join(" ");
    }
    return words_string;
}

function convertNumberToWords1(amount) {
    var words = new Array();
    words[0] = '';
    words[1] = 'One';
    words[2] = 'Two';
    words[3] = 'Three';
    words[4] = 'Four';
    words[5] = 'Five';
    words[6] = 'Six';
    words[7] = 'Seven';
    words[8] = 'Eight';
    words[9] = 'Nine';
    words[10] = 'Ten';
    words[11] = 'Eleven';
    words[12] = 'Twelve';
    words[13] = 'Thirteen';
    words[14] = 'Fourteen';
    words[15] = 'Fifteen';
    words[16] = 'Sixteen';
    words[17] = 'Seventeen';
    words[18] = 'Eighteen';
    words[19] = 'Nineteen';
    words[20] = 'Twenty';
    words[30] = 'Thirty';
    words[40] = 'Forty';
    words[50] = 'Fifty';
    words[60] = 'Sixty';
    words[70] = 'Seventy';
    words[80] = 'Eighty';
    words[90] = 'Ninety';
    amount = amount.toString();
    var atemp = amount.split(".");
    var number = atemp[0].split(",").join("");
    var n_length = number.length;
    var words_string = "";
    if (n_length <= 9) {
        var n_array = new Array(0, 0, 0, 0, 0, 0, 0, 0, 0);
        var received_n_array = new Array();
        for (var i = 0; i < n_length; i++) {
            received_n_array[i] = number.substr(i, 1);
        }
        for (var i = 9 - n_length, j = 0; i < 9; i++, j++) {
            n_array[i] = received_n_array[j];
        }
        for (var i = 0, j = 1; i < 9; i++, j++) {
            if (i == 0 || i == 2 || i == 4 || i == 7) {
                if (n_array[i] == 1) {
                    n_array[j] = 10 + parseInt(n_array[j]);
                    n_array[i] = 0;
                }
            }
        }
        value = "";
        for (var i = 0; i < 9; i++) {
            if (i == 0 || i == 2 || i == 4 || i == 7) {
                value = n_array[i] * 10;
            } else {
                value = n_array[i];
            }
            if (value != 0) {
                words_string += words[value] + " ";
            }
            if ((i == 1 && value != 0) || (i == 0 && value != 0 && n_array[i + 1] == 0)) {
                words_string += "Crores ";
            }
            if ((i == 3 && value != 0) || (i == 2 && value != 0 && n_array[i + 1] == 0)) {
                words_string += "Lakhs ";
            }
            if ((i == 5 && value != 0) || (i == 4 && value != 0 && n_array[i + 1] == 0)) {
                words_string += "Thousand ";
            }
            if (i == 6 && value != 0 && (n_array[i + 1] != 0 && n_array[i + 2] != 0)) {
                words_string += "Hundred and ";
            } else if (i == 6 && value != 0) {
                words_string += "Hundred ";
            }
        }
        words_string = words_string.split("  ").join(" ");
    }
    return words_string;
}
function convertNumberToWords2(amount) {
    var words = new Array();
    words[0] = '';
    words[1] = 'One';
    words[2] = 'Two';
    words[3] = 'Three';
    words[4] = 'Four';
    words[5] = 'Five';
    words[6] = 'Six';
    words[7] = 'Seven';
    words[8] = 'Eight';
    words[9] = 'Nine';
    words[10] = 'Ten';
    words[11] = 'Eleven';
    words[12] = 'Twelve';
    words[13] = 'Thirteen';
    words[14] = 'Fourteen';
    words[15] = 'Fifteen';
    words[16] = 'Sixteen';
    words[17] = 'Seventeen';
    words[18] = 'Eighteen';
    words[19] = 'Nineteen';
    words[20] = 'Twenty';
    words[30] = 'Thirty';
    words[40] = 'Forty';
    words[50] = 'Fifty';
    words[60] = 'Sixty';
    words[70] = 'Seventy';
    words[80] = 'Eighty';
    words[90] = 'Ninety';
    amount = amount.toString();
    var atemp = amount.split(".");
    var number = atemp[0].split(",").join("");
    var n_length = number.length;
    var words_string = "";
    if (n_length <= 9) {
        var n_array = new Array(0, 0, 0, 0, 0, 0, 0, 0, 0);
        var received_n_array = new Array();
        for (var i = 0; i < n_length; i++) {
            received_n_array[i] = number.substr(i, 1);
        }
        for (var i = 9 - n_length, j = 0; i < 9; i++, j++) {
            n_array[i] = received_n_array[j];
        }
        for (var i = 0, j = 1; i < 9; i++, j++) {
            if (i == 0 || i == 2 || i == 4 || i == 7) {
                if (n_array[i] == 1) {
                    n_array[j] = 10 + parseInt(n_array[j]);
                    n_array[i] = 0;
                }
            }
        }
        value = "";
        for (var i = 0; i < 9; i++) {
            if (i == 0 || i == 2 || i == 4 || i == 7) {
                value = n_array[i] * 10;
            } else {
                value = n_array[i];
            }
            if (value != 0) {
                words_string += words[value] + " ";
            }
            if ((i == 1 && value != 0) || (i == 0 && value != 0 && n_array[i + 1] == 0)) {
                words_string += "Crores ";
            }
            if ((i == 3 && value != 0) || (i == 2 && value != 0 && n_array[i + 1] == 0)) {
                words_string += "Lakhs ";
            }
            if ((i == 5 && value != 0) || (i == 4 && value != 0 && n_array[i + 1] == 0)) {
                words_string += "Thousand ";
            }
            if (i == 6 && value != 0 && (n_array[i + 1] != 0 && n_array[i + 2] != 0)) {
                words_string += "Hundred and ";
            } else if (i == 6 && value != 0) {
                words_string += "Hundred ";
            }
        }
        words_string = words_string.split("  ").join(" ");
    }
    return words_string;
}
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css" integrity="sha384-PsH8R72JQ3SOdhVi3uxftmaW6Vc51MKb0q5P2rRUpPvrszuE4W1povHYgTpBfshb" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.3/umd/popper.min.js" integrity="sha384-vFJXuSJphROIrBnz7yo7oB41mKfc8JzQZiCq4NCceLEaO4IHwicKwpJf9c9IpFgh" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/js/bootstrap.min.js" integrity="sha384-alpBpkh1PFOepccYVYDB4do5UnbKysX5WZXm3XxPqe5iKTfUKjNkCk9SaVuEZflJ" crossorigin="anonymous"></script>

<div class="controls">
  <div class="row">			   
    <div class="col-md-6 col-sm-4 col-xs-12"> 
      <label>Sharing Type</label>
      <select class="form-control seelectcss1 border" name="sharingType[]" required="">
        <option value="">Select</option>
        <option value="Single Sharing">Single Sharing</option>
        <option value="Two Sharing">Two Sharing</option>
        <option value="Three Sharing">Three Sharing</option>
        <option value="Four Sharing">Four Sharing</option>
      </select>				   
    </div>
  </div>
						
  <div class="row entry">
    <div class="col-md-3 col-sm-4 col-xs-12" style="padding-right:5px;">
      <div class="form-group" id="imm">
        <label class="control-label">Rent With Food :</label>
        <br>
        <input type="number" class="form-control nput border" name="withFood[]" id="withfood" onkeyup="word.innerHTML=convertNumberToWords(this.value)"> 
        <div id="word"></div>					
        <p class="custom-error amountError" style="display:none">Please Enter Amount</p>		
     </div>
    </div>
		
    <div class="col-md-3 col-sm-4 col-xs-12" style="padding-right:5px;">
      <div class="form-group" id="imm">
        <label class="control-label">Rent Without Food </label>
        <br>
        <input type="number" class="form-control nput border" name="withoutFood[]" id="withoutfood" onkeyup="word1.innerHTML=convertNumberToWords1(this.value)">	
       <div id="word1"></div>
      </div>
    </div>				
    <div class="col-md-3 col-sm-4 col-xs-12">
      <div class="form-group" id="imm">
        <label class="control-label">Advance Amount</label>
        <br>
        <input type="number" class="form-control  nput border" name="advance[]" id="advance" onkeyup="word2.innerHTML=convertNumberToWords1(this.value)">
       <div id="word2"></div>					
      </div>
    </div>
    
    <div class="col-md-3 col-sm-4 col-xs-12">
      <div class="form-group" id="imm">
        <button type="button" class="btn btn-success addSharingType" style="margin-top: 26px;height: 38px;" id="admore"><span class="glyphicon glyphicon-plus"></span> Add Sharing</button>
      </div>
    </div>
  </div>
</div>
<div class="sharingType"></div>
&#13;
&#13;
&#13;