开发者

Javascript function needs retouching

            function CopyValues(oDDL, sTargetId) {
                var arrValues = new Array();
                for (var i = 0; i < oDDL.options.length; i++) {
                    var curOption = oDDL.options[i];
                    if (curOption.selected)
                        arrValues.push(curOption.value);
                }
                document.getElementById(sTargetId).value += arrValues.join("\n");
            }

This javascript function works awesomely, it was provided in another question I asked months ago... This funct开发者_StackOverflow中文版ion transfers the value from a select box to the element id of my choice. I use the function like this:

onclick="CopyValues(this, 'subject');"

All I want now is that this value should be added IN THE BEGINNING of any other text in my textarea or input[type="text"]. Any ideas on how to change this to that? I can't do javascript myself.


Change

document.getElementById(sTargetId).value += arrValues.join("\n");

to

var targetElement = document.getElementById(sTargetId);
targetElement.value = arrValues.join("\n") + targetElement.value;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜