Millertime1 Posted August 16, 2014 Share Posted August 16, 2014 Hi, I'm having a problem with a hidden input value not changing on the browser after a request. I can change the value and alert or console log the new value but it won't change the DOM. Here's the section I'm having problems with: xhr.onload = function() { if (xhr.status === 200) { var data = JSON.parse(this.responseText); $(".token").attr('value', data.token); alert($(".token").val()); } else { console.log('Something went terribly wrong...'); } }; Link to comment https://forums.phpfreaks.com/topic/290485-dom-input-value-not-changing/ Share on other sites More sharing options...
fastsol Posted August 16, 2014 Share Posted August 16, 2014 What is the html for the element with class token? Link to comment https://forums.phpfreaks.com/topic/290485-dom-input-value-not-changing/#findComment-1487976 Share on other sites More sharing options...
Millertime1 Posted August 17, 2014 Author Share Posted August 17, 2014 <input type="hidden" name="token" id="token" value="sha512 hash"> All my other Ajax calls work off of .token so I'm lost at why it's not working. Link to comment https://forums.phpfreaks.com/topic/290485-dom-input-value-not-changing/#findComment-1487994 Share on other sites More sharing options...
fastsol Posted August 17, 2014 Share Posted August 17, 2014 Because you're tryning to call it on class="token" but in the html you use id="token". You need to change one or the other. Link to comment https://forums.phpfreaks.com/topic/290485-dom-input-value-not-changing/#findComment-1488006 Share on other sites More sharing options...
Millertime1 Posted August 17, 2014 Author Share Posted August 17, 2014 I decide to redirect instead since it better suits my application but I figure name and class were the same for an input since I can grab the element using a class selector. Link to comment https://forums.phpfreaks.com/topic/290485-dom-input-value-not-changing/#findComment-1488046 Share on other sites More sharing options...
CroNiX Posted August 17, 2014 Share Posted August 17, 2014 You can? Maybe you have before because you had name, id and class all the same. But in the case above there is no class "token" so it won't work. It would work if you used the ID $("#token").attr('value', data.token); Link to comment https://forums.phpfreaks.com/topic/290485-dom-input-value-not-changing/#findComment-1488058 Share on other sites More sharing options...
Millertime1 Posted August 17, 2014 Author Share Posted August 17, 2014 Never mind I did end up adding a class value. I've been away from my computer for awhile sorry. Link to comment https://forums.phpfreaks.com/topic/290485-dom-input-value-not-changing/#findComment-1488061 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.