javascript - Adding ID to button, but must change based on radio input selection -
edited add together html: not same since im not in office anymore, you'll idea.
the scenario have part of site users can pick 1 of multiple addresses have saved. id gets generated each address , need apply id button submit form.
i've gotten button receives id first click, if seek select different address, id not switch. how can have button utilize id of selected radio input? i'm using info attribute select this.
html: <div> <form> <input type="radio" data-js="select" id="test123" /> (id created dynamically) <label>address 1</label> <input type="radio" dat-js="select" id="test124" /> (id created dynamically) <label>address 2</label> </form> </div> <button class="address-continue">continue</button> var radioid = $('*[data-js]').attr('id'); var addrcontinue = $('.address-continue'); $('*[data-js]').click(function () { $(addrcontinue).attr('id', radioid); });
scenario: user clicks on address 1, id placed on button address 1. user made mistake, meant click on address 2. when click address 2, id on button doesn't change. remains same original click.
i need id on go on button alter based on proper radio selection.
since id unique utilize class
$('*[data-js]').click(function () { var addrbutton = $('.address-continue'); addrbutton.removeclass(test123); addrbutton.removeclass(test124); radioid = $('*[data-js]').attr('id'); addrbutton.addclass(radioid); });
also basic problem might because did not collect radioid in ur radio function hence wasn't updated seek this
$('*[data-js]').click(function () { var radioid = $('*[data-js]').attr('id'); $(addrcontinue).attr('id', radioid); });
javascript jquery html forms dynamic
No comments:
Post a Comment