insert to textarea from select menu |
insert to textarea from select menu |
owens4 |
Jan 28 2021, 11:42 AM
Post
#1
|
Group: Members Posts: 2 Joined: 28-January 21 Member No.: 27,755 |
This code works with input button but not in my select menu. It's returning drop.options[selectedIndex].value and not the actual value.
Input button: <input type="button" value="<script>" onclick="insert(window.putit,'<script>\n\n</script>\n')" ></button> The select menu: <form id="drop"> <select onchange="insert(window.putit,('drop.options[selectedIndex].value'))"> <option>Select HTML</option> <option value="insert(window.putit,'<script>\n\n</script>\n')"><script></option> <option value="insert(window.putit,'<iframe>\n\n</iframe>')"><iframe></option> <option value="insert(window.putit,'<textarea>\n\n</textarea>')"><textarea></option> </select></form> THX |
pandy |
Jan 28 2021, 12:36 PM
Post
#2
|
🌟Computer says no🌟 Group: WDG Moderators Posts: 20,733 Joined: 9-August 06 Member No.: 6 |
I'm not familiar with insert(), but I think you want the value of select, not option, as that will be the value of the chosen option. Try this.value.
Since I'm too lazy to read up on insert()... you can at least see that you get what you want. CODE <form id="drop"> <select onchange="alert(this.value)"> <option>Select HTML</option> <option value="insert(window.putit,'<script>\n\n</script>\n')"><script></option> <option value="insert(window.putit,'<iframe>\n\n</iframe>')"><iframe></option> <option value="insert(window.putit,'<textarea>\n\n</textarea>')"><textarea></option> </select></form> |
Christian J |
Jan 28 2021, 03:16 PM
Post
#3
|
. Group: WDG Moderators Posts: 9,661 Joined: 10-August 06 Member No.: 7 |
Input button: <input type="button" value="<script>" onclick="insert(window.putit,'<script>\n\n</script>\n')" ></button> The INPUT element has no end tag, so </button> shouldn't be there. Is value="<script>" valid HTML? pandy? Is insert() a function? I don't think it's a predefined method. |
pandy |
Jan 28 2021, 06:06 PM
Post
#4
|
🌟Computer says no🌟 Group: WDG Moderators Posts: 20,733 Joined: 9-August 06 Member No.: 6 |
Is value="<script>" valid HTML? pandy? I don't know. But I *think* so. It's CDATA. It says entities can be used, not that they must be used for certain characters. https://htmlhelp.com/reference/html40/values.html#cdata QUOTE Is insert() a function? I don't think it's a predefined method. Seems to be a method. I found just one page about it, that uses another syntax than the OP (no comma). Then I gave up. https://www.tutorialspoint.com/prototype/pr...ment_insert.htm |
Christian J |
Jan 29 2021, 09:04 AM
Post
#5
|
. Group: WDG Moderators Posts: 9,661 Joined: 10-August 06 Member No.: 7 |
Seems to be a method. I found just one page about it, that uses another syntax than the OP (no comma). Then I gave up. https://www.tutorialspoint.com/prototype/pr...ment_insert.htm Oh, that's part of the Prototype Javascript framework/library: https://www.tutorialspoint.com/prototype/pr...pe_overview.htm so it can't be used outside that. There is a real javascript method called insertBefore() that can be used without libraries, though it's a DOM method so it can't insert strings unless you turn them into text- or element nodes first. |
pandy |
Jan 29 2021, 01:04 PM
Post
#6
|
🌟Computer says no🌟 Group: WDG Moderators Posts: 20,733 Joined: 9-August 06 Member No.: 6 |
Oh, I didn't read to close. Whatever it is, the OP had it working, so I guess he has what it takes. He just asked for help to get the value from the select control.
|
owens4 |
Feb 1 2021, 11:40 AM
Post
#7
|
Group: Members Posts: 2 Joined: 28-January 21 Member No.: 27,755 |
I figured it out, I was overthinking it.
The code below inserted html tags to a textarea. The setframe() updated an iframe to render the html. Thanks... <script> function insert(el,ins) { //add code @ cursor// window.putit={}; if (el.setSelectionRange){ el.value = el.value.substring(0,el.selectionStart) + ins + el.value.substring(el.selectionStart,el.selectionEnd) + el.value.substring(el.selectionEnd,el.value.length); } else if (document.selection && document.selection.createRange) { el.focus(); var range = document.selection.createRange(); range.text = ins + range.text; } } function setframe() { //textarea 2 iframe// var enterHTML = enter.value; var iframe = document.getElementById('output'); iframe.contentWindow.document.open(); iframe.contentWindow.document.write(enterHTML); iframe.contentWindow.document.close(); } </script> <select class="button1" id="tags" name="tags" onchange="insert(window.putit,this.value),setframe()"> <option value="">INSERT HTML</option> <option value='<script>

</script>
'><SCRIPT></option> <option value='<style>

</style>
'><STYLE></option> <option value='<textarea></textarea>
'><TEXTAREA></option> <option value='<div id="">My Div</div>
'><DIV></option> <option value='<iframe src="" style="width:200px; height:200px; resize:both;"></iframe>
'><IFRAME></option> <option value='<button>my button</button>
'><BUTTON></option> <option value='<select id="">
<option>Select</option>
<option value="">1</option>
<option value="">2</option>
<option value="">3</option>
</select>
'><SELECT></option> <option value='<font size="7" color="red">Hello World</font>
'><FONT></option> <option value='<img src="https://thumbs.gfycat.com/DampAnyBubblefish-size_restricted.gif" border="0">
'><IMAGE></option> <option value='<audio controls autoplay loop>
<source src="https://pl3dxz-a.akamaihd.net/downloads/ringtones/files/mp3/pink-panther-6836.mp3" type="audio/mpeg">
</audio>
'><AUDIO></option> <option value='<a href="http://duckduckgo.com" target="_blank">Duck Duck Go</a>
'><LINK></option> <option value='<pre>

</pre>'><PRE></option> <!-- <option value=''></option> --> </select> |
Lo-Fi Version | Time is now: 27th April 2024 - 11:43 AM |