roughie Posted February 26, 2008 Share Posted February 26, 2008 I create markup on the fly via DOM scripting. Included is an input field of id = "mytimer". I fail to retrieve this field's value with the following code; It comes up with a zero value: var timer = document.getElementById("mytimer"); var tval = timer.getAttribute("value"); alert("Value of timer is now set to "+ tval); Yet, were I to use: alert("Value of timer is now set to "+ document.getElementById("mytimer").value); I succeed. Why this difference? Quote Link to comment Share on other sites More sharing options...
fnairb Posted February 26, 2008 Share Posted February 26, 2008 That is a trick question. Excerpt from: http://www.sitepoint.com/article/client-side-form-validation As the observant reader might have noted, value in elements.item.value is represented as an object. But could it have been reached by elements.item(i).getAttribute('value')? No, that just shows the default value (if any) in a tag, not the value entered by the user. Quote Link to comment Share on other sites More sharing options...
roughie Posted February 26, 2008 Author Share Posted February 26, 2008 fnairb - thanks much! Quote Link to comment 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.