使用javascript

时间:2016-12-30 04:22:31

标签: javascript split textbox

嗨我需要两个输入文本框字段。输入字段1表示文本数量    你想要的盒子。输入字段2以分割金额。所以,当我    提交我需要的金额在文本框中平均分配    使用javascript创建

function divideBy() 
{ 
        num1 = document.getElementById("amount").value;
        num2 = document.getElementById("secondNumber").value;
document.getElementById("result").innerHTML = num1 / num2;
}
</script>
    <script type='text/javascript'>
        function addFields(){
            // Number of inputs to create
            var number = document.getElementById("split").value;
            // Container <div> where dynamic content will be placed
            var container = document.getElementById("container");
            // Clear previous contents of the container
            while (container.hasChildNodes()) {
                container.removeChild(container.lastChild);
            }
            for (i=0;i<number;i++){
                // Append a node with a random text
                container.appendChild(document.createTextNode("Split " + (i+1)));
                // Create an <input> element, set its type and name attributes
                var input = document.createElement("input");
                input.type = "text";
                input.name = "split" + i;
				input.value="split" +i ;
                container.appendChild(input);
                // Append a line break 
                container.appendChild(document.createElement("br"));
				
				
				
				
				        num1 = document.getElementById("amount").value;
        num2 = document.getElementById("secondNumber").value;
document.getElementById("result").innerHTML = num1 / num2;

            }
        }
<body>
<form>
    <input type="text" id="split" name="split" value="">Number of splits: (max. 10)<br />
    <a href="#" id="filldetails"  onclick="addFields()">Create Text Box</a>

	<hr>
	
	
Amount : <input type="text" id="amount" /><br>
 <input type="hidden" id="secondNumber" value="2"  /><br>
<input type="button"  onClick="divideBy()" Value="Divide" />
</form>
<p>The Result is : <br>
<span id = "result"></span><br>
    <div value="" id="container"/>
</p>

</body>

0 个答案:

没有答案