MDanz Posted July 15, 2011 Share Posted July 15, 2011 var example = document.getElementById(number).value; var exampleid = "example"+number; document.getElementById(exampleid).innerHTML = example; i only want the variable 'example' to be 12 characters long then followed by three fullstops. How do i do this? Quote Link to comment https://forums.phpfreaks.com/topic/242068-subtr-help/ Share on other sites More sharing options...
Adam Posted July 15, 2011 Share Posted July 15, 2011 You made a typo, but you answered that yourself: .substr(). What have you tried so far? Quote Link to comment https://forums.phpfreaks.com/topic/242068-subtr-help/#findComment-1243135 Share on other sites More sharing options...
MDanz Posted July 15, 2011 Author Share Posted July 15, 2011 i tried this not working it should limit 'example' to 12 characters var example = document.getElementById(number).value; var exampleid = "example"+number; var example2 = example.substring(0,12); if(example2.length==12){ var example3 = example+"..."; } else { var example3 = example; } document.getElementById(exampleid).innerHTML = example3; Quote Link to comment https://forums.phpfreaks.com/topic/242068-subtr-help/#findComment-1243153 Share on other sites More sharing options...
Adam Posted July 15, 2011 Share Posted July 15, 2011 Ah, think you just needed to think simpler. Try this: var example = document.getElementById(number).value; var exampleid = example+number; if (example.length >= 12) { example = example.substr(0, 12) + '...'; } document.getElementById(exampleid).innerHTML = example; Key being the operator used, ">=" not "==". Edit: removed the quotes in the "exampleid" declaration. Quote Link to comment https://forums.phpfreaks.com/topic/242068-subtr-help/#findComment-1243190 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.