Jump to content

Recommended Posts

Hi to to all. Good day. I have a problem regarding passing function value to designated textbox when button is clicked

 

 

This is my code in looping button and text box.

 

 

<?php 
for($i=0;$i<5;$i++)
{?>
<div>
<input type="text" name="timervalue" id="timers" value="" class="responseTime">
<input type="submit" name="itstimer[<?php echo $i; ?>]" value="Start" id="start"/>
</div>
<?php }; ?>


//function 

startTimer = function(elemeto) {
    time=0;
    setInterval((function() {
      if(flagger ==true)
      {
    time++;
      }
    count = time;
    document.getElementById(elemeto).value = count;
    // $('#timers').val(count);

    }), 1000);
    // document.getElementById('start').hidden = true;
    
};

//jquery to execute

$('input[type=submit]').on('click', function(e) {
    if($(this).val() == 'Start')
     {   
         name = $(this).attr('name');
         timer =  name.match(/\[(.*)\]/)[1];
        
         timerField = $('input[name="timervalue['+timer+']"]');
         timerField = 'timers';
         return startTimer(timerField);
      }
   });
});


</script>

The problem is that, when i click the 2nd button, the value passed in textbox 1. I want that when I click 2nd button, value will pass to 2nd textbox, when I click the first button, then it will pass value to first textbox, and so on.
 
Please see attached file. Thank you :)
 

 

post-181301-0-45374600-1457657029_thumb.jpg

Have you looked into giving each of the "timervalue" inputs a different name and id?

 

Side note: the id attribute in HTML is supposed to be unique. More information can be found here:

https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/id

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.