• 締切済み

javascriptを使ったフォームをCGIで取得できない

フォームに名前、フリ仮名、性別(ラジオボタン)、生年月日(選択メニュー)があり、下記は確認ページで、javascriptを使って、表示されます。でもCGI(以下にあります)では名前のみ取得できあとの値は表示されません。どうすればよいでしょうか ---- <html lang="ja"> <head> <script type="text/javascript"><!-- function Cng(){ var st = window.opener.document.user.name.value; window.document.kuser.kname.value = st; var st1 = window.opener.document.user.furigana.value; window.document.kuser.kfurigana.value = st1; var sex=window.opener.document.all.user.sex if(sex[0].checked) {window.document.kuser.ksex.value ="男性"} else if(sex[1].checked) {window.document.kuser.ksex.value ="女性"} var st11 = window.opener.document.all.user.year.value; window.document.kuser.kyear.value = st11; var st12 = window.opener.document.all.user.month.value; window.document.kuser.kmonth.value = st12; var st13 = window.opener.document.all.user.day.value; window.document.kuser.kday.value = st13;}  //--> </script> </head> <body onLoad="Cng();"> <form name="kuser" action="./5-2.cgi" method="post" enctype="text/plain"> 氏名:    <input type="text" name="kname" value="" size="30"><br><br> ふりがな:  <input type="text" name="kfurigana" value="" size="30"><br><br> 性別:    <input type="text" name="ksex" value="" size="7"><br><br> 生年月日:   西暦 <input type="text" name="kyear" value="" size="10"> 年   <input type="text" name="kmonth" value="" size="5"> 月   <input type="text" name="kday" value="" size="5"> 日<br><br> <tr><td colspan="2" align="right">         <input type="submit" value="送信">   <input type="button" value="戻る"> ----- (CGI) #! c:/perl/bin/perl # フォームデータの取得 if($ENV{'REQUEST_METHOD'} eq 'POST') { read(STDIN, $query, $ENV{'CONTENT_LENGTH'}); } else { $query = $ENV{'QUERY_STRING'}; } foreach $pair (split(/&/, $query)){ ($key, $value)=split(/=/, $pair); $value=~tr/+/ /; $value=~s/%([0-9a-fA-F][0-9a-fA-F])/chr(hex($1))/eg; $FORM{$key}=$value; } # サーバー出力 print <<END; Content-type: text/html <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"> <html> <head><title>ふぉーむでーた</title></head> <body> <h1>フォームデータ</h1> <table border="1"> <tr><th>フォーム要素</th><th>データ</th></tr> END foreach $key (keys %FORM){ print "<tr><th>$key</th><td>$FORM{$key}</td></tr>\n"; } print <<END; </table> </body> ---

みんなの回答

noname#39970
noname#39970
回答No.1

前に 似たような質問を見た事があったけど それはただ単にformの部品のタグの閉じ方だとか「"」の閉じ方を誤っていて認識されていないというオチだった。 その辺り、よく確認してみたらどうだろう

houseroof
質問者

補足

自己レスです。下記の文を削除したらOKでした。 enctype="text/plain"

関連するQ&A

  • javascript のsyntaxについて

    HTML文書でJavaScriptを使い、任意の数の<input type="text" .. > タグを表示させようとしています。 添付の写真の上の方にある"number of parts" の部分が、その任意の数を入れる所で、隣のボタンを押すと関数 "inputBox()" を呼ぶようにしてあります。 入力した任意の数だけwindow.document.write() で書かれた入力ボックスが出てくると思ったのですが、出てきません。 maxQty=window.document.getElementById("qty").value; によって取得した任意の数をforループで使っていますが、これが働いていないようです。 というのは、この文をコメントアウトして具体的な数を入れるとちゃんとその数だけの入力用の行が出てくるからです。 どう考えてもこの文に間違いはないように思われますが、どこがおかしいのか、どなたか教えてくださいませんでしょうか。 以下にソースコードをコピーします。 <!doctype html public "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title> makeBOMtables.html</title> <script type="text/javascript"> </script> </head> <body bgcolor="navy" style="font-size:16pt; color:yellow"> <center> <h3>company name</h3> <h2>Product BOM List making Program</h2> <form method="POST" action="makeBOMtables.php"> <table border="1"> <tr><td>product number</td> <td> description </td><td>number of parts</td><td></td></tr> <tr> <td><input type="text" size="16" style="font-size:16pt" id="prodNum" name="prodNumx"/></td> <td><input type="text" size="50" style="font-size:16pt" id="prodName" name="prodNamex" /></td> <td><input type="text" size="5" style="font-size:16pt" id="qty" name="qtyx"/></td> <td><input type="button" value="make BOM" onclick="inputBox()"></td> </tr> </table> </br> <script > var maxQty; function inputBox(){ window.document.write("<html><head></head><body bgcolor='navy' style='font-size:16pt; color:yellow'><center>"); window.document.write("<table border='1'>"); window.document.write("<tr> <th>item #</th><th>part number</th> <th>description </th><th>we need</th>"); window.document.write(" <th>we have</th> <th></br></th></tr>"); // table header maxQty=window.document.getElementById("qty").value; for (var count=1; count<=maxQty; count++){ window.document.write("<tr>"); window.document.write("<td><input type='text' size='5' style='font-size:12pt' id='item"+ count + "' name='itemx"+ count +"' value="+ count +" /></td>" ); window.document.write("<td><input type='text' size='16' style='font-size:12pt' id='partNum"+ count + "' name='partNumx"+ count +"' /></td>" ); window.document.write("<td><input type='text' size='50' style='font-size:12pt' id='partName"+ count + "' name='partNamex"+ count +"' /></td>" ); window.document.write("<td><input type='text' size='5' style='font-size:12pt' id='qtyN"+ count +"' name='qtyNx"+ count + "' /></td>" ); window.document.write("<td><input type='text' size='5' style='font-size:12pt' id='qtyH"+ count +"' name='qtyHx"+ count + "' /></td>" ); window.document.write("<td><input type='submit' value='end input'/> </td>"); window.document.write("</tr>"); }// end for window.document.write("</center></body></html>"); } </script> </form> </center> </body> </html> また、入力行が表示されるのは、なぜか別のページですが、これは今は気にしません。 詳しい方がいらっしゃいましたら、よろしくお願いいたします。

  • javascriptでフォームの値の計算

    javascript1か月目の初心者です。 7つのテキストフィールドに数値を代入させて合計と平均(最後には標準偏差)を計算しようと思ってます。 以下のように考えましたが、うまくいきません。 strが文字列として?扱われてしまっているようです。 strをevalで囲んでみてもダメです。 詳しい方教えてください。 <!--スクリプト1--> <SCRIPT LANGUAGE="JavaScript"> <!-- function f_check() { if(document.F1.num1.value!=""&&document.F1.num2.value!=""&&document.F1.num3.value!=""&&document.F1.num4.value!=""&&document.F1.num5.value!="" &&document.F1.num6.value!=""&&document.F1.num7.value!=""){ str=0 for(var i = 0;i<document.F1.length;i++){ str+=document.F1[i].value; } alert('合計は'+str+"です"); avrg = (str)/document.F1.length; alert('平均は'+avrg+'です'); //ここから標準偏差の計算(略)。 } // --> </SCRIPT> <form method="post" name="F1" onSubmit="return f_check()"> 数値を入れてください<input type="text" name="num1" size="5"><br> 数値を入れてください<input type="text" name="num2" size="5"><br> 数値を入れてください<input type="text" name="num3" size="5"><br> 数値を入れてください<input type="text" name="num4" size="5"><br> 数値を入れてください<input type="text" name="num5" size="5"><br> 数値を入れてください<input type="text" name="num6" size="5"><br> 数値を入れてください<input type="text" name="num7" size="5"><br> <INPUT TYPE=SUBMIT VALUE="平均をとる"></FORM>

  • javascriptによる計算

    テキストボックス「a1~6」の値とテキストボックス「b1~6」に入力された値を足し算してテキストボックス「c1~6」(例…c[i] = a[i] + b[i])を計算するJavaScriptを作成しているのですが、結果がundefinedになってしまい上手くいきません。どうやったら動くのかどうかご教授ください。 以下ソース↓ <script language ="JavaScript"> function plus() { var intResult = 0; for (i=1; i<=6; i++){ intResult[i] = 0; if (!isNaN(document.forms["A"].all["a"+i].value) && !isNaN(document.forms["B"].all["b"+i].value)){ intResult[i] += parseInt(document.forms["A"].all["a"+i].value); intResult[i] += parseInt(document.forms["B"].all["b"+i].value); } <table border = 1> <tr> <td> <table border = 1> <tr> <td> <form name="A"> <input type = "text" size = 5 name = "a1"></input> </td> <td> <input type = "text" size = 5 name = "a2"></input> </td> <td> <input type = "text" size = 5 name = "a3"></input> </td> </tr> <tr> <td> <input type = "text" size = 5 name = "a4"></input> </td> <td> <input type = "text" size = 5 name = "a5"></input> </td> <td> <input type = "text" size = 5 name = "a6"></input> </form> </td> </tr> </table> </td> <td> <table boeder = 1> <tr> <input type = "button" onClick="plus()" value = "+"></input> </tr> </table> </td> <td> <table border = 1> <tr> <td> <form name = "B"> <input type = "text" size = 5 name = "b1"></input> </td> <td> <input type = "text" size = 5 name = "b2"></input> </td> <td> <input type = "text" size = 5 name = "b3"></input> </td> </tr> <tr> <td> <input type = "text" size = 5 name = "b4"></input> </td> <td> <input type = "text" size = 5 name = "b5"></input> </td> <td> <input type = "text" size = 5 name = "b6"></input> </form> </td> </tr> </table> </td> </tr> </table> 答え <form name = "C"> <table border = 1> <tr> <td> <input type = "text" size = 5 name = "c1"></input> </td> <td> <input type = "text" size = 5 name = "c2"></input> </td> <td> <input type = "text" size = 5 name = "c3"></input> </td> </tr> <tr> <td> <input type = "text" size = 5 name = "c4"></input> </td> <td> <input type = "text" size = 5 name = "c5"></input> </td> <td> <input type = "text" size = 5 name = "c6"></input> </td> </tr> </table> </form> </body> document.C.all["c"+i].value = intResult[i]; } } </script>

  • 2つのフォームに値を入れて計算

    2つのフォームを作り、その2つを計算したいのですがオブジェクトの指定の仕方がエラーが出てしまい(オブジェクトを指定してくださいと出ます)わかりません。 どうか教えてください。 ちなみにforなどは使わなくても大丈夫ですのでよろしくお願いします。 function kei() { var kei1 = 0; kei1=eval(document.A.a11.value) * eval(document.B.b21.value) ; document.C.c11.value = kei1; } <table border = 1> <form name="A"> <tr> <td> <input type = "text" size = 5 name = "a11"></input> </td> <td> <input type = "text" size = 5 name = "a12"></input> </td> <td> <input type = "text" size = 5 name = "a13"></input> </td> </tr> <tr> <td> <input type = "text" size = 5 name = "a21"></input> </td> <td> <input type = "text" size = 5 name = "a22"></input> </td> <td> <input type = "text" size = 5 name = "a23"></input> </td> </tr> </form> </table> <table boeder = 1> <tr> <input type = "button" onClick="kei()" value = "×"></input> </tr> </table> <table border = 1> <form name="B"> <tr> <td> <input type = "text" size = 5 name = "b21"></input> </td> <td> <input type = "text" size = 5 name = "b22"></input> </td> <td> <input type = "text" size = 5 name = "b23"></input> </td> </tr> <tr> <td> <input type = "text" size = 5 name = "b31"></input> </td> <td> <input type = "text" size = 5 name = "b32"></input> </td> <td> <input type = "text" size = 5 name = "b33"></input> </td> </tr> </form> </table> <table border = 1> <form name="C"> <tr> <td> <input type = "text" size = 5 name = "c11"></input> </td> <td> <input type = "text" size = 5 name = "c12"></input> </td> <td> <input type = "text" size = 5 name = "c13"></input> </td> </tr> <tr> <td> <input type = "text" size = 5 name = "c21"></input> </td> <td> <input type = "text" size = 5 name = "c22"></input> </td> <td> <input type = "text" size = 5 name = "c23"></input> </td> </tr> </form> </table>

  • 現在javascriptでチェックボックスで選択した項目のvalueを

    現在javascriptでチェックボックスで選択した項目のvalueを次ページに渡すものを作成しています。 1つだけ選択すると正常に値が動くのですが、複数選択すると後に選択したほうの値だけが入ってしまいます。 複数選択した場合に選択した全てのvalueが入るようにするにはどうしたらいいでしょうか? 【1ページ目ソース】 <html> <head> <title>1page</title> </head> <body> <form name="F1" onsubmit="window.open('2page.html','_blank','');return false;"> A<input type="text" id="tanka1"> B<input type="checkbox" name="che1" id="check1" value="1">1 <input type="checkbox" name="che1" id="check1" value="2">2 <input type="checkbox" name="che1" id="check1" value="3">3 <input type="submit" value="送信" onclick=check();></form> </body> </html> 【2ページ目ソース】 <html> <head> <title>2page</title> <script> window.onload=function (){ document.F2.tanka1.value=window.opener.document.F1.tanka1.value; if (window.opener.document.F1.che1[0].checked)document.F2.check1.value=1; if (window.opener.document.F1.che1[1].checked)document.F2.check1.value=2; if (window.opener.document.F1.che1[2].checked)document.F2.check1.value=3; } </script> </head> <body> <form name="F2"> A<input type="text" id="tanka1"> B<input type="text" id="check1"> <br><br> </body> </html>

  • javascript 関数についての質問

    javascriptで 入力された日付を元に30日後、40日後、60日後、90日後の日付を表示したいのですが、 作った関数が1回しか使えませんTT(?)何回も使えるようにしたいです! 初歩的な質問ですみませんが、どうすればよいでしょうか? <html> <head> <title>ねこ</title> <script> function Kekka(days){ Yobi = new Array("日","月","火","水","木","金","土"); Date = new Date(document.form.y.value, document.form.m.value -1, document.form.d.value); d = Date.getDate(); Date.setDate(d+days); y = Date.getFullYear(); m = Date.getMonth()+1; d = Date.getDate(); w = Date.getDay(); str1 = y+"年"+m+"月"+d+"日("+Yobi[w]+"曜日)"; //土曜日か日曜日だったら次の月曜の日付もとる if(w == 0){ w = 1; Date.setDate(d+days+1); d = Date.getDate(); } else if(w == 6){ w = 1; Date.setDate(d+days+2); d = Date.getDate(); } str2 = y+"年"+m+"月"+d+"日("+Yobi[w]+"曜日)"; return str1,str2; } function CLR(){ document.form.y.value="";document.form.m.value="";document.form.d.value=""; document.form.v1.value="";document.form.v1_2.value=""; document.form.v2.value="";document.form.v2_2.value=""; document.form.v3.value="";document.form.v3_2.value=""; document.form.v4.value="";document.form.v4_2.value=""; document.form.v5.value="";document.form.v5_2.value=""; } function Test(){ Kekka(30); document.form.v1.value = str1; document.form.v1_2.value = str2; Kekka(40); document.form.v2.value = str1; document.form.v2_2.value = str2; } </script> </head> <body> てすとなう<br><br> <form name="form"> <input type="text" name="y" size="4">年 <input type="text" name="m" size="2">月 <input type="text" name="d" size="2">日 <input type="button" value="start" onclick="Test()"> <input type="button" value="CLR" onclick="CLR()"> <br><br> 30日後:<input type="text" name="v1" size="27">→<input type="text" name="v1_2" size="27"><br> 40日後:<input type="text" name="v2" size="27">→<input type="text" name="v2_2" size="27"><br> 60日後:<input type="text" name="v3" size="27">→<input type="text" name="v3_2" size="27"><br> 90日後:<input type="text" name="v4" size="27">→<input type="text" name="v4_2" size="27"><br> 3ヶ月後:<input type="text" name="v5" size="27">→<input type="text" name="v5_2" size="27"><br> <br><br> </form> </body> </html>

  • JavaScriptの質問です。

    JavaScriptの質問です。 下記フォームで、 1番が入力されると、 2、3番目のエリアがグレーになって入力不可になる方法を教えてください。 <tr> <th align="right">1番</th> <td><input type="text" size="10" name="shopid" id="shopid" /></td> </tr> <tr> <th align="right">2番</th> <td><input type="text" size="10" name="area" /></td> </tr> <tr> <th align="right">3番</th> <td><input type="text" size="10" name="business" /></td> </tr> <tr> よろしくお願いします。

  • テーブルの行削除について

    以前、テーブルの行追加について教えてもらい出来ましたが 逆に、追加された行を削除する方法を教えてください。 <HTML> <HEAD> <META HTTP-EQUIV="Content-Type" CONTENT="text/html; CHARSET=Shift_JIS"> <TITLE>行追加・削除</TITLE> </HEAD> <BODY> <TABLE BORDER="1" id="Table1"> <TR> <TH>タイトルA</TH> <TH>タイトルB</TH> </TR> <TR> <TD><INPUT TYPE="text" SIZE="18" MAXLENGTH="18" NAME="A" VALUE=""></TD> <TD><INPUT TYPE="text" SIZE="18" MAXLENGTH="18" NAME="B" VALUE=""></TD> </TR> </TABLE> <INPUT TYPE="button" VALUE="行追加" onclick="addRow()"> <INPUT TYPE="button" VALUE="行削除"> <script language="JavaScript"> function addRow() { var tbl = document.getElementById("Table1").firstChild; if (!tbl.tagName) { tbl = document.getElementById("Table1"); } var tr = document.createElement("tr"); var td1 = document.createElement("td"); var tx1 = document.createElement("input"); tx1.setAttribute("type","text"); tx1.setAttribute("size","18"); tx1.setAttribute("maxlength","18"); tx1.setAttribute("name","Cn"); tx1.setAttribute("value",""); td1.appendChild(tx1); var td2 = document.createElement("td"); var tx2 = document.createElement("input"); tx2.setAttribute("type","text"); tx2.setAttribute("size","18"); tx2.setAttribute("maxlength","18"); tx2.setAttribute("name","Cn"); tx2.setAttribute("value",""); td2.appendChild(tx2); tr.appendChild(td1); tr.appendChild(td2); tbl.appendChild(tr); } </script> </BODY> </HTML>

  • javascriptで取得した値を、FORMで送信する

    いつもお世話になっております。 jspからwindow.openを使い、別ウインドウを表示しました。 別ウインドウでの質問です。 javascriptで前のページ(jsp)の情報を受け取り、それを次のページ(jsp)へFORM(POST)で送りたいのですが、うまくいきません。 ご教授下さい。 <HTML> <HEAD> <script type="text/javascript"> <!-- function sent() { var num = window.opener.document.aaa.number01.value; ここで前ウィンドウの情報を取得しています return num; } function sub() { document.bbb.submit(); } // --> </script> </HEAD> <BODY onload="sub()"> <form name="bbb" METHOD="POST" action="http://okwave.jp"> <input type="hidden" name="timeid" value=""> <input type="hidden" name="number00" value="1"> <input type="hidden" name="number01" value="sent()"> <!--<input type="hidden" name="number01" value="204038054776">--> 当たり前ですが、コメントにしている部分にすると次のページでうまくいきます。 </form> </BODY> </HTML>

  • textbox間の結合時、空白の時は、スペースを省きたい

    <script type="text/javascript"> <!-- function ketugou(){     document.f.q.value=document.f.t1.value+" "+document.f.t2.value+" "+document.f.t3.value+" "+document.f.t4.value+" "+document.f.t5.value; } //--> </script> <form name="f"> キーワードを入力:<br> <input type="text" size="55" name="t1"><br> <input type="text" size="55" name="t2"><br> <input type="text" size="55" name="t3"><br> <input type="text" size="55" name="t4"><br> <input type="text" size="55" name="t5"><br> <input type="button" name="connect" value="結合" onClick="ketugou()"><br> 結合時の内容を表示:<br> <input type="txt" name="q" size="55" maxlength="255" ><br> </form> で、空白のテキストボックスの場合は、スペース(" ")なしで、 結合させたいんですが、どうしたら、良いのでしょうか?