Member_2_5230414
asked on
Text does not wrap around drop down selections.
Im trying to make it so when a user selects a colour from the drop down menu. it wraps the code around the highlighted text.
<select id="color" onchange="setColor(this.va lue);">
<option value="" selected="selected">Change Color</option>
<option value="black" style="background-color:bl ack;">Blac k</option>
<option value="red" style="background-color:re d;">Red</o ption>
<option value="yellow" style="background-color:ye llow;">Yel low</optio n>
<option value="pink" style="background-color:pi nk;">Pink< /option>
<option value="green" style="background-color:gr een;">Gree n</option>
<option value="orange" style="background-color:or ange;">Ora nge</optio n>
<option value="purple" style="background-color:pu rple;">Pur ple</optio n>
<option value="blue" style="background-color:bl ue;">Blue< /option>
<option value="beige" style="background-color:be ige;">Beig e</option>
<option value="brown" style="background-color:br own;">Brow n</option>
<option value="teal" style="background-color:te al;">Teal< /option>
<option value="navy" style="background-color:na vy;">Navy< /option>
<option value="maroon" style="background-color:ma roon;">Mar oon</optio n>
<option value="limeGreen" style="background-color:li megreen;"> Lime Green</option>
<option value="white">White</optio n>
</select>
Below is the javascript for this
<select id="color" onchange="setColor(this.va
<option value="" selected="selected">Change
<option value="black" style="background-color:bl
<option value="red" style="background-color:re
<option value="yellow" style="background-color:ye
<option value="pink" style="background-color:pi
<option value="green" style="background-color:gr
<option value="orange" style="background-color:or
<option value="purple" style="background-color:pu
<option value="blue" style="background-color:bl
<option value="beige" style="background-color:be
<option value="brown" style="background-color:br
<option value="teal" style="background-color:te
<option value="navy" style="background-color:na
<option value="maroon" style="background-color:ma
<option value="limeGreen" style="background-color:li
<option value="white">White</optio
</select>
Below is the javascript for this
function setColor(color) {
var textbox = document.getElementById('inputforum');
textbox.value += "[color=" + color + "][/color]";
}
function setsize(size) {
var textbox = document.getElementById('inputforum');
textbox.value += "[size=" + size + "][/size]";
}
function initialise() {
var element = document.getElementById('element-id');
if (element && element.style)
element.style.display = 'none';
}
function toggleDisplay(element) {
var style;
if (typeof element == 'string')
element = document.getElementById(element);
if (element && (style = element.style))
style.display = (style.display == 'none') ? '' : 'none';
}
if (!document.getElementById)
document.getElementById = function() {return null;};
function wrapText(el, openTag, closeTag) {
if (el.setSelectionRange) {
// W3C/Mozilla
el.value = el.value.substring(0,el.selectionStart) + openTag + el.value.substring(el.selectionStart,el.selectionEnd) + closeTag + el.value.substring(el.selectionEnd,el.value.length);
}
else if (document.selection && document.selection.createRange) {
// IE code goes here
el.focus(); //or else text is added to the activating control
var range = document.selection.createRange();
range.text = openTag + range.text + closeTag;
}
}
ASKER
tried the above code and sadly just adds it to the end line of text
ah. Apologies. The code for the select did not work at all. I now understand your question. I'll find some code later. You need to use document.selection and more. Why invent the hot water when tinyEDIT will do the job.
ASKER
It was a learing proccess tvia using php ect :)...
I would love to finish off re inventing hotwater ;)
I would love to finish off re inventing hotwater ;)
ASKER
humm took a look and gone right over my head...
With buttons i do this: <input type='button' value='B' name='btnBold' onclick='wrapText(document .getElemen tById(' ;inputforu m'),&# 39;[b]' ;,'[/b ]');'/ >
Anyway i can apply it to the dropdowns?
With buttons i do this: <input type='button' value='B' name='btnBold' onclick='wrapText(document
Anyway i can apply it to the dropdowns?
Sorry - I could not read your code on my mobile
Yes of course. Not clever of me not to scroll down to see you have the means to do what you want
onChange='wrapText(documen t.getEleme ntById( 9;inputfor um'),& #39;[color =\''+this. form.color .value+'\' ]', 9;[/b]' ;);'/>
for example
Let me know how you get along I am so very busy - I will have more time tomorrow
Yes of course. Not clever of me not to scroll down to see you have the means to do what you want
onChange='wrapText(documen
for example
Let me know how you get along I am so very busy - I will have more time tomorrow
ASKER
Tried it and didnt do anything ...not even inset [color.....][/color]
Hard to read it - should have fixed the &39; and no need to pass the form.color since there are no form tags and we are IN the select
try (watch the single quotes)
<select id="color" onChange="if (this.selectedIndex>0)wrap Text(docum ent.getEle mentById(' inputforum '),'[color =\''+this. value+'\'] ','[/color ]');"/>
try (watch the single quotes)
<select id="color" onChange="if (this.selectedIndex>0)wrap
ASKER
how do i get rid of the quotes??
Itried and both 1ns i delete dont work
Itried and both 1ns i delete dont work
sorry I do not understand what you mean.
ASKER
sorry.
The current output is [colour='red'] i need it to just be [color=red]
I have attempted to take out the quotes and then the code does not work
The current output is [colour='red'] i need it to just be [color=red]
I have attempted to take out the quotes and then the code does not work
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Open in new window