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? 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? 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; 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. Link to comment https://forums.phpfreaks.com/topic/242068-subtr-help/#findComment-1243190 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.