アプリ版:「スタンプのみでお礼する」機能のリリースについて

セレクトボックスで選択された値を見て、
text入力欄の背景色を変えたいのですが、
JavaScriptの書き方がよくわかりませんので
教えていただけないでしょうか。

-----------------------------------------
セレクトボックス(SELECT_AREA)の値選択時に
onChengeで呼び出して
テキスト入力欄(MEMBER_NAME)の色を変えたい。

<html:select property="SELECT_AREA">

<html:text property="MEMBER_NAME" size="100" maxlength="20" style="background:#FF0000" />

-----------------------------------------------

よろしくお願いします。

A 回答 (1件)

セレクトボックス・テキストエリアを下記のように設定した場合(htmlで)



<select name="sec01" size="1" tabindex="0" onchange="javaScript:selectChange()">
<option value=""></option>
<option value="a">a</option>
<option value="b">b</option>
<option value="c">c</option>
</select>

<textarea name="txtArea" rows="2" cols="20" tabindex="0"></textarea>

javaScriptの関数 selectChange() を

function selectChange()
{
selectValue = document.all["sec01"].value;
txtStyle = document.all["txtArea"].style;
if (selectValue == "a") txtStyle.background = "red";
if (selectValue == "b") txtStyle.background = "yellow";
if (selectValue == "c") txtStyle.background = "black";
if (selectValue == "") txtStyle.background = "white";
}

と書けば、テキストエリアの背景色は変化するようになります。
    • good
    • 0

お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!