BTC USD 61,059.6 Gold USD 4,272.40
Time now: Jun 1, 12:00 AM

Jquery: Getting values from textboxes not registered from DOM?

Jack Hard

Freshie
Messages
10
Joined
Dec 19, 2012
Messages
10
Reaction score
0
Points
3
I have a series of text boxes that are dynamically generated on a html page through jquery. Now since these are not registered with DOM, i am not able to get their values.

$('.inputText').each(function() {
total += Number($(this).val());
**);

console.log(total);

total is not printed in above code. How can i get and set values to elements not registered with DOM?
 
I have a series of text boxes that are dynamically generated on a html page through jquery. Now since these are not registered with DOM, i am not able to get their values.

$('.inputText').each(function() {
total += Number($(this).val());
**);

console.log(total);

total is not printed in above code. How can i get and set values to elements not registered with DOM?

You need to call calculation function after generating the said code..
hope this will help.. replace "**" with close bracket.

Code:
<div id="#code_generated">
generated code here
</div>

<script type="text/javascript">
$(document).ready(function() {
  function calculate_generated_code() {
     var total = 0;
     $('.inputText').each(function() {
          var val = parseInt($(this).attr("value"));
          total = total + val;
     **);
     alert(total);
  **;
  function generated_code() {
     $("div#code_generated").html("<input class='inputTex' value='0'>");
  **;

  // call
  generated_code();
  calculate_generated_code();
**);
</script>
 
Back
Top
Log in Register