简体   繁体   中英

How to set text area display text based on Cookie value on page load?

I have a text area in the middle of my page like so:

<TEXTAREA NAME="carowner_notes" ROWS=6 COLS=25 ALIGN="center" value="decodeURIComponent('test%0D%0A%0D%0Atest')" onkeydown="check_length(50)" onkeyup="check_length(50)">
decodeURIComponent(test%0D%0A%0D%0Atest)
</TEXTAREA>

I am trying to set the display contents of the box to be the decoded string as the page loads. Is there an easy way to do this?

Right now my box looks like this:

在此处输入图片说明

I need it to look like this:

在此处输入图片说明

SOLUTION:

HTML:

<TEXTAREA NAME="carowner_notes" ROWS=6 COLS=25 ALIGN="center" value="decodeURIComponent('test%0D%0A%0D%0Atest')" onkeydown="check_length(50)" onkeyup="check_length(50)">
</TEXTAREA>
<SCRIPT>$("#carowner_notes").ready(function(){
                                document.getElementsByName('carowner_notes')[0].value = decodeURIComponent('test%0D%0A%0D%0Atest');
                                });
</SCRIPT>

I am using PL/SQL so this shows passing in the variable:

v_notes_cookieval varchar2 := 'test%0D%0A%0D%0Atest';
htp.formTextareaOpen('carowner_notes','6', '25', 'center',     'value="decodeURIComponent('''||v_notes_cookieval||''')" onkeydown="check_length(50)" onkeyup="check_length(50)"');
htp.formTextareaClose;
htp.script('$("#carowner_notes").ready(function(){
                                document.getElementsByName(''carowner_notes'')[0].value = decodeURIComponent('''||v_notes_cookieval||''');
                                });');

You can run this code on page load.

var textarea = document.querySelectorAll('textarea')[0]

textarea.value = decodeURIComponent('test%0D%0A%0D%0Atest')

Obviously, you'll probably want to assign an ID to the TEXTAREA node in the event that you have more than one TEXTAREA node.

Also, the 'test%0D%0A%0D%0Atest' doesn't have to be hardcoded. You can pull that from the query/hash of the URL, or elsewhere.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM