###前提・実現したいこと
idがcate_serch_inpのテキストボックスに文字入力があったときに
alertでsel[0]を表示させたいです。
最終的には配列selをコメントアウトしてる部分のように
前述のテキストボックスに1文字入力、削除するごとに
for文で回して適切なドロップダウンリストを表示させたいです
###発生している問題・エラーメッセージ
表示が出ない
###該当のソースコード
<html> <body> <script type="text/javascript"> $res=null; $(function(){ $('#add_product_frm').keyup(function(){ var fd=new FormData($(this).get(0)); $.ajax({ "url":"select.php", "data":fd, "type":"post", "processData": false, "contentType": false, }).done(function(response){ res=response; }); e.preventDefault(); }); }); </script> </head> <body> <div id="main"> <input type="radio" name="div_change" id="add_product_inp"><a>商品の追加</a> <div id="add_product_div"> <form id="add_product_frm" action="masta_add.php" method="post"> <input name="cate_serch_inp" id="cate_serch_inp" type="text" placeholder="商品の種類を選択" autocomplete="off" required><br> <script type="text/javascript"> if(res!=null){ sel = res.split(","); alert(sel[0]); } /*document.write("<select>"); for(i=0;i<sel.length;i++){ document.write("<option>"+sel[i]+"</option>"); } document.write("</select>");*/ </script> </body> </html>
###試したこと
alertでresを表示することはできましたのでresまで
"文字列1,文字列2,文字列3......"
という形式でresに入っていることはわかりました。
###補足情報(言語/FW/ツール等のバージョンなど)
より詳細な情報
回答1件
あなたの回答
tips
プレビュー