![](http://oshiete.xgoo.jp/images/v2/pc/qa/question_title.png?e8efa67)
No.2ベストアンサー
- 回答日時:
javascriptですね。
簡単なサンプルを書くと、こう。
<p><input type="text" id="A"></p>
<p>
<input type="button" value="テスト1"
onclick="document.getElementById('A').value='テスト'">
<!-- idを付けておいて、そのidで対象を特定、
inputなので value の値を設定する -->
<input type="button" value="テスト2">
<input type="button" value="テスト3">
</p>
No.5
- 回答日時:
解決しているみたいだが、何となくアレなので
#3の修正。どうやら入力された値はgetAttributeとかfirstChild.nodeValueでは取得できないようで.valueである必要があるようだ。
回答前のテストしてから投稿直前に変えちゃったもんで・・・(汗
========
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dt …
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ja" lang="ja">
<head>
<title>Q3167024 テストケース1</title>
<script type="text/javascript">
var textarea;
function init(){
textarea = document.getElementById("sample");
}
function InputTextByString(str){
textarea.value = str;
}
function AppendTextByString(str){
textarea.value += str;
}
function InputTextByButton(Button){
textarea.value = Button.value;
}
function AppendTextByButton(Button){
textarea.value += Button.value;
}
</script>
</head>
<body onload="init();">
<h1>テストケース</h1>
<!-- textareaに空白がないとfirstChildが取得できなかったもんで-->
<p><textarea id="sample" cols="100" rows="10"> </textarea></p>
<h2>パターン1</h2>
<p><input type="button" value="テスト" onclick="InputTextByString('あああ');" /><input type="button" value="テスト1" onclick="InputTextByString('テスト');" /><input type="button" value="テスト2" onclick="InputTextByString('いいい');" /></p>
<h2>パターン2</h2>
<p><input type="button" value="テスト" onclick="AppendTextByString('あああ');" /><input type="button" value="テスト1" onclick="AppendTextByString('テスト');" /><input type="button" value="テスト2" onclick="AppendTextByString('いいい');" /></p>
<h2>パターン3</h2>
<p><input type="button" value="テスト" onclick="InputTextByButton(this);" /><input type="button" value="テスト1" onclick="InputTextByButton(this);" /><input type="button" value="テスト2" onclick="InputTextByButton(this);" /></p>
<h2>パターン3</h2>
<p><input type="button" value="テスト" onclick="AppendTextByButton(this);" /><input type="button" value="テスト1" onclick="AppendTextByButton(this);" /><input type="button" value="テスト2" onclick="AppendTextByButton(this);" /></p>
<p><input type="text" id="TEXTBOX" /></p>
<p><input type="button" id="APPENDTEXTAREA" value="テキストボックスの内容を追記" onclick="AppendTextByString(document.getElementById('TEXTBOX').value);"/></p>
</body>
</html>
=========
No.4
- 回答日時:
・テキストボックスに表示される
・テキストボックスに打ち込まれる(勝手に打ち込まれる)
の違いを詳しく教えてもらえますか?
代替案っぽいものの提案ですが、
ボタンを押したときではなく、HTMLファイルを表示したときにすでに表示されてる状態にするなら、
わざわざJavaScriptを使わなくても、
<input type="text" name="A" value="テスト">
でいいと思います。
No.3
- 回答日時:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "
http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dt …<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ja" lang="ja">
<head>
<title>Q3167024 テストケース1</title>
<script type="text/javascript">
var textarea;
function init(){
textarea = document.getElementById("sample");
}
function InputTextByString(str){
textarea.firstChild.nodeValue = str;
}
function AppendTextByString(str){
textarea.firstChild.nodeValue += str;
}
function InputTextByButton(Button){
textarea.firstChild.nodeValue = Button.getAttribute("value");
}
function AppendTextByButton(Button){
textarea.firstChild.nodeValue += Button.getAttribute("value");
}
</script>
</head>
<body onload="init();">
<h1>テストケース</h1>
<!-- textareaに空白がないとfirstChildが取得できなかったもんで-->
<p><textarea id="sample" cols="100" rows="10"> </textarea></p>
<h2>パターン1</h2>
<p><input type="button" value="テスト" onclick="InputTextByString('あああ');" /><input type="button" value="テスト1" onclick="InputTextByString('テスト');" /><input type="button" value="テスト2" onclick="InputTextByString('いいい');" /></p>
<h2>パターン2</h2>
<p><input type="button" value="テスト" onclick="AppendTextByString('あああ');" /><input type="button" value="テスト1" onclick="AppendTextByString('テスト');" /><input type="button" value="テスト2" onclick="AppendTextByString('いいい');" /></p>
<h2>パターン3</h2>
<p><input type="button" value="テスト" onclick="InputTextByButton(this);" /><input type="button" value="テスト1" onclick="InputTextByButton(this);" /><input type="button" value="テスト2" onclick="InputTextByButton(this);" /></p>
<h2>パターン3</h2>
<p><input type="button" value="テスト" onclick="AppendTextByButton(this);" /><input type="button" value="テスト1" onclick="AppendTextByButton(this);" /><input type="button" value="テスト2" onclick="AppendTextByButton(this);" /></p>
<p>質問者さんの勘違いも念のために想定して色々作ってみる</p>
</body>
</html>
No.1
- 回答日時:
参考URLをご覧ください。
ボタンを押すのではなく、カーソルで触れると表示されるタイプで、
JavaScriptを使ったものですが、どうでしょうか?
参考URL:http://www.geocities.co.jp/HeartLand-Kaede/3853/ …
お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!
似たような質問が見つかりました
- JavaScript javascriptのちょっとした動作不良(原因は突き止めたのですが) 1 2023/06/15 19:58
- Access(アクセス) アクセス 意図せずサブプロシージャを移動してしまうのを止めたい 1 2022/09/02 09:19
- Access(アクセス) Access IF文でテーブルに存在しない場合の処理について 2 2022/10/10 18:09
- Visual Basic(VBA) visual basic初心者です。 visual studioで電卓を作成しています。 実行時にテ 1 2023/02/08 00:18
- Visual Basic(VBA) ExcelVBAでユーザーフォームでテキストボックスなどからセルに連続して入力するコーディングの際の 2 2022/06/29 22:51
- Visual Basic(VBA) Excel VBA 複数選択したリストボックスからテキストボックスに転記したいです。 3 2023/03/19 18:31
- Access(アクセス) テキストボックスの値をテーブルに入力したい 2 2022/06/28 12:08
- その他(パソコン・スマホ・電化製品) ワードでテキストボックス内の文字を連動させない方法 2 2023/02/09 16:56
- Visual Basic(VBA) Vba 電卓 一文字消すボタン 3 2022/05/04 13:40
- Visual Basic(VBA) VB.net フォーム 親子 1 2022/07/04 19:00
関連するカテゴリからQ&Aを探す
おすすめ情報
デイリーランキングこのカテゴリの人気デイリーQ&Aランキング
-
ラジオボタンが両方とも選択で...
-
「value」に2つの値をセットす...
-
iPhoneでセレクトボックスが選...
-
INPUT TYPE
-
チェックボックス選択で(3つ)...
-
ある条件での必須入力について
-
ラジオボタンを選択済みにする...
-
FORMのselectの選択肢を最初か...
-
テキストボックスについて
-
チェックボックスとセレクトボ...
-
[HTML]プルダウンメニューの横...
-
wordの数式について 定積分を書...
-
VB.net データーグリッドビュー...
-
VB初心者。小数点以下の表示で...
-
拡張子'html'と'htm'はどっちが...
-
proftpdで困ってます。
-
別formのhidden項目を自form値...
-
チェックボックスの返す値
-
ブックマークからのアクセスを...
-
誕生日のカウントダウン日数を...
マンスリーランキングこのカテゴリの人気マンスリーQ&Aランキング
-
ラジオボタンが両方とも選択で...
-
「value」に2つの値をセットす...
-
INPUT TYPE
-
select値をhiddenのvalueに渡し...
-
FORMのselectの選択肢を最初か...
-
チェックボックスとセレクトボ...
-
リストボックス(multipleなsel...
-
ラジオボタンを選択済みにする...
-
OPTIONタグにループは使えない...
-
検索窓をクリックすると文字が...
-
NNでうまく動きません
-
チェックボックス選択で(3つ)...
-
フォームで絞込み検索機能を持...
-
メールフォームのプルダウンメ...
-
HTML プルダウンメニューの選択...
-
チェックボックスの余白を指定...
-
<select>タグの幅設定
-
フォームよりCGIへ複数の値をPO...
-
HP上の選択ボタンの選択肢リス...
-
プルダウンメニューにテキスト...
おすすめ情報