samuel_lopez Posted March 11, 2016 Share Posted March 11, 2016 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 Quote Link to comment https://forums.phpfreaks.com/topic/300977-pass-value-to-designated-textbox-using-button/ Share on other sites More sharing options...
cyberRobot Posted March 11, 2016 Share Posted March 11, 2016 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 Quote Link to comment https://forums.phpfreaks.com/topic/300977-pass-value-to-designated-textbox-using-button/#findComment-1531915 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.