textarea doesnt return value

2019-09-10 06:17发布

Im using a code editor codepress in all of my textareas, but no textarea return a value. I think the different name and id is the problem. Example:

<textarea name="content_text" rows="20" cols="50" class="codepress sql" id="myCpWindow"></textarea>

I have read somewhere in here to use a hidden input to transfer the textarea's value, but i cant do it myself!

ayhelp?

5条回答
小情绪 Triste *
2楼-- · 2019-09-10 06:57

= drop the id.

Why are your names and id different? (you shouldn't do that in general btw). I assume you're using the name for your stuff and just taking the id because it was on their stuff. While i've never used codepress, most scripts like this (at least, well built ones) will build off of the class (and not the ID) so go ahead and drop the id and see if that works. cheers.

查看更多
小情绪 Triste *
3楼-- · 2019-09-10 07:00

This worked for me.
If the name and id of the textarea are the same, it breaks the javascript. For the textarea i just assign an ID and I add a hidden input field with the name I wish to collect in the form process; then using the onsubmit to assign the codepress to the hidden input like this:

<form action="something" onsubmit="codeText.value = codeTextArea.getCode();">
<textarea id="codeTextArea" rows="20" cols="50" class="codepress java"></textarea>
<input type="hidden" name="codeText"/>
<input type="Submit">
</form>
查看更多
再贱就再见
4楼-- · 2019-09-10 07:03

Both answers didnt work...

In the support forum of codepress i found this:

<input type="submit" onclick="textareaID.textarea.value = textareaID.getCode();" value="save" />  

but i cant understand.

Here is the link of discution

查看更多
手持菜刀,她持情操
5楼-- · 2019-09-10 07:06

no onsubmit you just need to turnoff the codepress

<form action="something" onsubmit="content_text.toggleEditor();">
  <textarea name="content_text" rows="20" cols="50" class="codepress sql" id="myCpWindow">  
  </textarea>
  <input type="Submit">
</form>
查看更多
我命由我不由天
6楼-- · 2019-09-10 07:17

You need to call textarea_id.getCode()

So you probably want something like this:

<form action="something" onsubmit="this.content_hidden = content_text.getCode();">
<input type="hidden" name="content_hidden">
<textarea name="content_text" rows="20" cols="50" class="codepress sql" id="myCpWindow"></textarea>
<input type="Submit">
</form>
查看更多
登录 后发表回答