0

Comment box works well with <textarea> but I need to use div in place of it. here is text area code:

<textarea class="commentMark" id="commentMark-<?php  echo $row['p_id'];?>" onblur="if (this.value=='') this.value = 'Write a comment'" onfocus="if (this.value=='Write a comment') this.value = ''" onKeyPress="return SubmitComment(this,event)" wrap="hard" name="commentMark" style=" background-color:#fff; overflow: hidden;" cols="60">Write a comment</textarea>

I tried to replace it with contenteditable div

<div class="commentMark" id="commentMark-<?php  echo $row['p_id'];?>" onblur="if (this.value=='') this.value = 'Write a comment'" onfocus="if (this.value=='Write a comment') this.value = ''" onKeyPress="return SubmitComment(this,event)" wrap="hard" name="commentMark" style=" background-color:#fff; overflow: hidden;" cols="60">Write a comment</div>

But in text area when I press enter comment get posted. While in div when I enter it does not make any effect.

also div appears with clicking on the "comment" button

user2129623
  • 2,167
  • 3
  • 35
  • 64
  • 2
    why not just use a `textarea`? You can create a new line when the enter key is pressed and avoid the form being submitted - http://stackoverflow.com/questions/9671688/preventing-enter-from-submitting-form-but-allow-it-on-textarea-fields-jquery – martincarlin87 Oct 09 '13 at 11:08
  • Please use native javascript or jQuery to attach event handlers. Over use of `onclick` `onkeypress` etc makes me a sad panda. – Rory McCrossan Oct 09 '13 at 11:08
  • @martincarlin87: I have issue with textare. Using `div` I can give `Read more` option in the text. But in textarea I could not – user2129623 Oct 09 '13 at 11:18
  • what does the read more part do? Generally speaking, you should be able to achieve what you want with a textarea and if desired, style it not to look like one. – martincarlin87 Oct 09 '13 at 11:20
  • 1
    @martincarlin87: Yes you are right. When textarea has content more the specific size then it only few line should appear. When user click on `view more` then only entire content should appear. Please see http://stackoverflow.com/questions/19270535/adding-readmore-option-in-textarea – user2129623 Oct 09 '13 at 11:24
  • Ah, I understand better now, having the different elements makes it a lot tricker than if it was just one body of text rather than an `h2` and normal text. You could try something like http://www.appelsiini.net/projects/jeditable ? – martincarlin87 Oct 09 '13 at 11:29
  • @martincarlin87: I could not understand how it can be helpful to me! :( – user2129623 Oct 09 '13 at 11:32
  • hmm, I thought it might have been helpful, basically when initialised on your div, it would make it editable for you so that you didn't have to worry about converting from textarea to div yourself. – martincarlin87 Oct 09 '13 at 11:41

0 Answers0