Irresistable Posted January 7, 2010 Share Posted January 7, 2010 var deletelink = document.createElement('a'); var t = document.createTextNode("X"); deletelink.setAttribute('href', '#'); deletelink.setAttribute('style', 'float:right;'); new_row.innerHTML = element.value; That code gets the value of the element, and puts it in a div. The last line is probably all you need, editting anything before that with the string will probably defeat the process. What I'm trying to do, is display a certain amount of characters. Lets say 30 for example. If the string is over 30, reduce by 3, and add "..." Or whatever will be possible. I know it's possible to do it with php, but not in the way I'm wanting to do it. "element.value" is the value, so maybe creating a var eg: var reduced = element.value.reduced to 30; new_row.innerHTML = reduced However, that's not correct. You may get the idea. Can anyone help? Thanks. Quote Link to comment Share on other sites More sharing options...
trq Posted January 7, 2010 Share Posted January 7, 2010 var reduced; if (element.value.length > 30) { reduced = element.value.substr(0, element.value.length-3)+'...'; } else { reduced = element.value; } Quote Link to comment Share on other sites More sharing options...
Irresistable Posted January 7, 2010 Author Share Posted January 7, 2010 Thanks. Maybe I wasn't clear enough. If the string is bigger than 30 characters, to shorten it down to 30. Take away 3 and add "..." Thanks. Quote Link to comment Share on other sites More sharing options...
trq Posted January 7, 2010 Share Posted January 7, 2010 Yeah sorry, that's what I was meant to do. var reduced; if (element.value.length > 30) { reduced = element.value.substr(0, 30)+'...'; } else { reduced = element.value; } Don't really undertsand how you couldn't do that yourself from my example. Javascripts substr() is no different to php's except it is a method of the string object. 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.