• ベストアンサー

IEで動作確認もFirefoxで動作しない

皆さんお世話になってます。Javascript精通していません。 どうぞご指導ください。 ソースは下記になります。Firefox3.0で確認すると何も表示されません。IEだとうまく表示されました。原因を教えていただけますでしょうか? HTML <img src="./images/btn_estimate.gif" onclick="recalculate();"/> [合計]<label id="price"><?= $price ?></label> JavaScript function recalculate() { var total = 0; document.getElementById("price").innerText = ""; if (document.form.design.checked == true) { total = total + 10000; } total = total + document.form.pages.value * 5000; if (document.form.form_func.checked == true) { total = total + 3000; } document.getElementById("price").innerText = total; }

質問者が選んだベストアンサー

  • ベストアンサー
  • yambejp
  • ベストアンサー率51% (3827/7415)
回答No.4

formにnameをつけるのはいいことないのでやめた方がよいです。 idでいきましょう。 総じてこんなかんじ。やはり問題はinnetText関係じゃないですかね <script> function recalculate() { var f=document.getElementById("form_estimate"); var total = 0; document.getElementById("price").innerHTML = ""; if (f.design.checked) total += 10000; total += parseInt(f.pages.value) * 5000; if (f.form_func.checked) total += 3000; document.getElementById("price").innerHTML = total; } </script> <form id="form_estimate"> <input type="checkbox" name="design" value="1" /> <input type="text" name="pages" size="3" maxlength="3" value="0" /> <input name="form_func" type="checkbox" value="1" /> <img src="./images/btn_estimate.gif" onclick="recalculate(this.parentNode);"/> [合計]<label id="price"><?= $price ?></label> </form>

ogesatakao
質問者

お礼

完璧なソースをありがとうございました。 ここまで親切にしていただいて大変うれしいです。 おかげ様で、無事動作を確認いたしました。 ありがとうございました。

全文を見る
すると、全ての回答が全文表示されます。

その他の回答 (3)

  • zxcv0000
  • ベストアンサー率56% (111/196)
回答No.3

何箇所かで使われている oElement.innerText は、InternetExplorer 依存だそうです。 参考URLの内容で試してみては?

参考URL:
http://www.tohoho-web.com/js/dom.htm#inner
ogesatakao
質問者

お礼

おっしゃるとおり、 innerText がFirefoxで使えない事が原因のようです。 参考URLありがとうございました。

全文を見る
すると、全ての回答が全文表示されます。
  • SAYKA
  • ベストアンサー率34% (944/2776)
回答No.2

No1の言う通り全部ソースがないからわからないけど 操作したいフォームが現れる前に実行しちゃってるんじゃない? head内に書いてあるとbodyが現れる前に実行しちゃうから全部読み込まれたら実行されるように細工する必要があるよ そうじゃなく?

ogesatakao
質問者

補足

確かにhead部分に書いてあります。 ただIEだとうまく動作するんですが・・。 ちなみにどのように細工しておく必要がございますか?

全文を見る
すると、全ての回答が全文表示されます。
  • fujillin
  • ベストアンサー率61% (1594/2576)
回答No.1

肝心のForm部分が提示されていないので、ほとんどわかりませんが・・・ document.form.~の指定方法で、formという識別名がタグのformとかぶっているのが、一因となっている可能性があります。 さらに、全体に、"price"の指定で行っているような、idを利用した指定方法にしておいたほうが良いと思われます。

ogesatakao
質問者

補足

回答ありがとうございます。 確かに form部分name="form"となっていましたので"form"以外にしたのですが、かわらずでした。 ちなみにform部分は下記です。 <form name="form_estimate"> <input type="checkbox" name="design" value="1" /> <input type="text" name="pages" size="3" maxlength="3" value="0" /> <input name="form_func" type="checkbox" value="1" /> <img src="./images/btn_estimate.gif" onclick="recalculate();"/> [合計]<label id="price"><?= $price ?></label> </form>

全文を見る
すると、全ての回答が全文表示されます。

関連するQ&A

  • javascriptがIEだけ動作しません

    javascript初心者です。 サイトに、ラジオボタンの選択に応じて、 値をテキストボックスに返す仕組みを作りたいと思っています。 Chrome,FireFox,Operaでは正しく動作していすが、 IEでは、テキストボックスのみ表示され、 ラジオボタンと選択肢が非表示になってしまいます。 お手数ですが、ご教示をお願いしたく、 よろしくお願いします。 <form> <script type="text/javascript"> NoDHTML=(!document.all && !document.getElementById) || (navigator.userAgent.indexOf('Opera/6.')>=0) || (navigator.userAgent.indexOf('Opera 6.')>=0); function changeMenu2(n) { if (NoDHTML) return; if (n==100) { if (document.all) { document.all['TNAME'].style.display='none'; document.all['TNAME2'].style.display='none'; } else if (document.getElementById) { document.getElementById('TNAME').style.display='none'; document.getElementById('TNAME2').style.display='none'; } with(document.forms[0].TNAME) { options.length=1; options[0].text=''; options[0].value=''; } document.forms[0].TNAME2.value=''; } else { if (document.all) { document.all['TNAME2'].style.display='none'; document.all['TNAME'].style.display='none'; } else if (document.getElementById) { document.getElementById('TNAME2').style.display='none'; document.getElementById('TNAME').style.display='none'; } if (n==0) { document.forms[0].course_name.value='りんご'; document.forms[0].course_price.value='600円'; } else if (n==1) { document.forms[0].course_name.value='メロン'; document.forms[0].course_price.value='1000円'; } else if (n==2) { document.forms[0].course_name.value='マンゴー'; document.forms[0].course_price.value='5000円'; } } document.forms[0].TNAME.options[0].selected=true; } if (!NoDHTML) { document.write( ' <label><input type="radio" name="TNAME2" onclick="changeMenu2(0);" onkeypress="return(true)" />リンゴ</label><br />'+ ' <label><input type="radio" name="TNAME2" onclick="changeMenu2(1)" onkeypress="return(true)" />メロン</label><br />'+ ' <label><input type="radio" name="TNAME2" onclick="changeMenu2(2);" onkeypress="return(true)" />マンゴー</label>'+ '<input type="hidden" name="course_name">' ); } </script> <!-- ★★ここの部分はCSSで強制的に見えないようになっています --> <select name="TNAME" id="TNAME" style="display:none !important;"> <option value="" selected="selected" style="display:none !important;"></option> </select> <!-- /★★ここの部分はCSSで強制的に見えないようになっています --> <script type="text/javascript"> if (!NoDHTML) { document.write( '<input type="hidden" name="TNAME2" id="TNAME2" value="" size="20" />' ); } </script> <br /> <br /> <br /> <!-- ★★ここに"course_priceの値が表示されます --> <input type="text" name="course_price" readonly="readonly"> <!-- /★★ここに"course_priceの値が表示されます --> </form>

  • javascriptでラジオボタンのが変更できない

    javascriptを勉強中なのですが 練習で下記のような麻雀の計算をしてくれるサイトを作ってみましたがうまく反応しません。 http://tegarude.sakura.ne.jp/mafu/form.html できない点は、例えば、ロンの項目で面前のチェックの時、ツモの項目にいいえが入りますが、 その後、ツモの項目で平和のチェックをいれようとしてもチェックが入りません。 javascriptで操作するようにしたのですがどうもうまくいきません。 単純なこと簡単なことなのかもしれませんが どなたかご教授願えませんでしょうか? ソースコードが長いのでjavascriptの記述のみ載せています。 サンプルのURLを参考にして下さい。 function on(){ //ロン・ツモ・待ち・雀頭の値を取得 function mjk01(m1,m2){ for (j=0; j<m1.length; j++){ if(m1[j].checked){ m2.innerHTML=m1[j].value; } } } mjk01(document.form1.radio2,document.getElementById("a00")); mjk01(document.form1.radio3,document.getElementById("a01")); mjk01(document.form1.radio4,document.getElementById("a02")); mjk01(document.form1.radio5,document.getElementById("a03")); //formプロパティの省略 formt=document.form1; //ロン項目設定 if(formt.radio2[0].checked){ formt.radio3[3].checked=true; formt.radio7[0].checked=true; formt.radio9[0].checked=true; formt.radio11[0].checked=true; formt.radio13[0].checked=true; } if(formt.radio2[1].checked){ formt.radio3[3].checked=true; formt.radio4[0].checked=true; formt.radio5[2].checked=true; formt.radio6[0].checked=true; formt.radio8[0].checked=true; formt.radio10[0].checked=true; formt.radio12[0].checked=true; } if(formt.radio2[2].checked){ formt.radio3[3].checked=true; } //ツモ項目設定 if(formt.radio3[0].checked){ formt.radio2[3].checked=true; formt.radio4[0].checked=true; formt.radio5[2].checked=true; formt.radio6[0].checked=true; formt.radio8[0].checked=true; formt.radio10[0].checked=true; formt.radio12[0].checked=true; } if(formt.radio3[1].checked){ formt.radio2[3].checked=true; formt.radio4[0].checked=true; formt.radio5[2].checked=true; } if(formt.radio3[2].checked){ formt.radio2[3].checked=true; } //面子の設定 function mentsu(m1,m2,m3){ if(m1[0].checked){ m2[1].value=4; m2[2].value=16; m2[3].value=8; m2[4].value=32; } if(m1[1].checked){ m2[1].value=2; m2[2].value=8; m2[3].value=4; m2[4].value=16; } for(i=0; i<m2.length; i++){ if(m2[i].checked){ m3.innerHTML=m2[i].value; } } } mentsu(document.form1.radio7,document.form1.radio6,document.getElementById("a04")); mentsu(document.form1.radio9,document.form1.radio8,document.getElementById("a05")); mentsu(document.form1.radio11,document.form1.radio10,document.getElementById("a06")); mentsu(document.form1.radio13,document.form1.radio12,document.getElementById("a07")); //小計をすべて数字に変換 num0=document.getElementById("a00").innerHTML; num1=document.getElementById("a01").innerHTML; num2=document.getElementById("a02").innerHTML; num3=document.getElementById("a03").innerHTML; num4=document.getElementById("a04").innerHTML; num5=document.getElementById("a05").innerHTML; num6=document.getElementById("a06").innerHTML; num7=document.getElementById("a07").innerHTML; num0 = parseFloat(num0); num1 = parseFloat(num1); num2 = parseFloat(num2); num3 = parseFloat(num3); num4 = parseFloat(num4); num5 = parseFloat(num5); num6 = parseFloat(num6); num7 = parseFloat(num7); //総合計の算出 document.getElementById("total").innerHTML=num0+num1+num2+num3+num4+num5+num6+num7; }

  • 自動計算をIEとFireFoxで動かすには?

    いつもお世話になっています。 フォームに入力した値を10で割った数を答えを自動で計算して、別フォームに出力する部分で、FireFoxでは自動計算されるのですがIEでは計算が行われませんでしたx_x; 【ソース】******************************* <script type="text/javascript"> <!-- function keisan(){ // 設定開始 // 商品1 var price1 = document.form1.goods1.value / 10; // 単価を設定 document.form1.field1.value = price1; // 小計を表示 // 合計を計算 var total = price1; // 設定終了 document.form1.field_total.value = total; // 合計を表示 } *********************************** 解決方法をご教授頂けたら幸いです。 何卒よろしくお願い致します。

  • ラジオボタンとフォーム検索の結び付け

    スマホ用にゲームの攻略サイトを作りたいと思っています。 ■やりたいこと■ 値段はわかっているが名前がわからないアイテムの判別。 まずラジオボタンで「武器」か「防具」を選びます。 そして値段を入れると 「武器・600」=勇者の剣 「防具・600」=盾 といったように選んだラジオボタンによって同じ数字でも 表示結果を変えたいと考えています。 ラジオボタン「武器」を選ぶと検索用ボタン「button_1」が表示される。 ラジオボタン「防具」を選ぶと検索用ボタン「button_2」が表示される。 button_1と2の切り分けによってfunctionの切り分けを行っている状態です。 ■問題点■ 「防具」を押す→600を入力→「盾」が表示される→「武器」を押す→「勇者の剣」が表示されてしまう。 チェックボックスの選択を変えても表示結果は再度検索するまでそのまま、 もしくはチェックボックスを選び直した際は前回入力した数値は消えるなど対策を取りたいです。 そもそも他にもっといいやり方があるなど改善案をご教授いただきたいです。 よろしくお願いします。 【HTML】 <body> <div class="top_form"> <form name="test"> <label><input type="radio" name="radio_btn" value="buki" onclick="func();" checked="checked" />武器</label> <label><input type="radio" name="radio_btn" value="bougu" onclick="func();" />防具</label><br> <input id="test_form" type="tel" name="num"> <input id="button_1" type="button" value="button_1" onClick="func()"> <input id="button_2" type="button" value="button_2" onClick="func2()"> </form> </div> <div id="result"></div> </body> 【CSS】 <style> .top_form { width:300px; margin:0 auto; margin-top:30px; } #test_form { width:250px; height:30px; font-size:14px; margin-top:14px; } #button_1 { text-decoration: none; -moz-appearance: none; -webkit-appearance: none; appearance: none; width:90px; height:44px; margin-top:15px; } #button_2 { text-decoration: none; -moz-appearance: none; -webkit-appearance: none; appearance: none; width:90px; height:44px; margin-top:15px; background-color:#36C; } #result { border:solid 1px #666666; margin:0 auto; height:50px; width:200px; font-size:20px; line-height:50px; text-align:center; margin-top:30px; } </style> 【javascript】 <script> function func() { radio = document.getElementsByName('radio_btn'); if (radio[0].checked) { //button_1が出る document.getElementById('button_1').style.display = ""; document.getElementById('button_2').style.display = "none"; } else if (radio[1].checked) { //button_2が出る document.getElementById('button_1').style.display = "none"; document.getElementById('button_2').style.display = ""; } var url = ""; if (document.test.num.value == "600") { url = "勇者の剣"; } document.getElementById('result').innerHTML = url; } window.onload = func; function func2() { radio = document.getElementsByName('radio_btn'); var url = ""; if (document.test.num.value == "600") { url = "盾"; } document.getElementById('result').innerHTML = url; } </script>

  • JavaSの追加計算

    function keisan(){ // 設定開始 var price1 = document.form1.kazu.value; // 合計を計算 if (price1 < 10000) { var total = parseInt(price1)*44/10000; } else { var total = parseInt(price1)*45/10000; } else if // 設定終了 document.form1.field_total.value = total; // 合計を表示 } // --> </SCRIPT> 上記に追加で*22/10000の計算を入れたいのですがどうしたらいいのですようか? 初心者なので申し訳ございませんがご教授お願い致します。

  • Firefoxで表示できないのは何故でしょう?

    お世話になります IE6、Operaでは表示できたのですがFirefoxでは表示できませんでした(><) 何か見落としがあるのでしょうか? <script language="javascript"> <!-- window.onload = function() { n=document.getElementById("div1").innerText; if(n == "a0"){ document.getElementById("img1").style.display = "block"; document.getElementById("img1").style.top = "100px"; document.getElementById("img1").style.left = "100px"; } if(n == "a"){ document.getElementById("img2").style.display = "block"; document.getElementById("img2").style.top = "100px"; document.getElementById("img2").style.left = "200px"; } } //--> </script> <div id="div1">a</div> <form action="test.cgi" method="post"> <input type="hidden"name="a" value="leap_day"> <input type="image" src="sample0.gif" id="img1" style="position:absolute;display:none;"> </form> <form action="test.cgi" method="post"> <input type="hidden"name="b" value="leap_day"> <input type="image" src="sample1.gif" id="img2" style="position:absolute;display:none;"> </form> n=document.getElementById("div1").innerText; if(n == "a0"){ } if(n == "a") { } を消すと表示はできるのですが・・・

  • 計算結果を変数に代入

    とあるサービスの料金計算フォームを制作しています。 特定の場合のみ料金が割引されるので、if構文で条件分岐してみたところ、 計算結果(小計)にはうまく反映されるのですが、いくつかの小計を合計すると、 if構文で分岐する前の(つまり割り引き前の)値段で計算されてしまいます。 // 小計1 var total_01 = document.form_test.price_01.options [document.form_test.price_01.selectedIndex].value * document.form_test.goods_01.options [document.form_test.goods_01.selectedIndex].value + document.form_test.price_02.options [document.form_test.price_02.selectedIndex].value * document.form_test.goods_02.options [document.form_test.goods_02.selectedIndex].value ; // 小計1 document.form_test.F-total_01.value = total_01; // 小計1を表示 if (document.form_test.price_01.options [document.form_test.price_01.selectedIndex].value != 0 && document.form_test.price_02.options [document.form_test.price_02.selectedIndex].value != 0) {document.form_test.F-total_01.value = total_01 - 500;} // 両方で-500 if (total_01 <= 0) {document.form_test.F-total_01.value = 0;} // 合計 var total_all = total_01 + total_02 + total_034; // 合計 document.form_test.F-total_all.value = total_all; // 合計を表示 小計を表示する <INPUT TYPE="text" NAME="F-total_01" VALUE="0"> に出てきた値を、そのまま次の計算に代入できれば 解決するのではないかと思うのですが、行き詰ってしまいました。 どうかアドバイスをよろしくお願いいたします。

  • Javascriptによるフォームの選択表示について教えてください。

    Javascriptによるフォームの選択表示について教えてください。 概要としてはカートCGIのお客様情報入力欄のカスタマイズを行なっています。 別の場所への発送を希望される場合において(1)、(2)、(3)のラジオボタンを作り、それぞれ選択によって該当のフォームを表示するところまではできました。 問題は、(1)→1箇所、(2)→3箇所、(3)→5箇所とフォームを作ったところ、入力ページが表示された時点で(1)(2)(3)全ての表示がされた状態で表示されます。 ちなみに、その際にラジオボタンを選択すると(1)(2)(3)それぞれに対応したフォームが表示され切り替わります。 実際にやりたいことは、ページが表示された時点で(1)のフォームのみ表示されるようにし、(2)(3)とラジオボタンを選択された際にそこで初めて(2)(3)のそれぞれのフォームを表示したいと思っています。 以下はソースです。 ■Javascript <script type="text/javascript"> function func1() { document.getElementById("sele1").style.display="inline"; document.getElementById("sele1").disabled=false; document.getElementById("sele2").style.display="none"; document.getElementById("sele2").disabled=true; document.getElementById("sele3").style.display="none"; document.getElementById("sele3").disabled=true; } function func2() { document.getElementById("sele1").style.display="none"; document.getElementById("sele1").disabled=true; document.getElementById("sele2").style.display="inline"; document.getElementById("sele2").disabled=false; document.getElementById("sele3").style.display="none"; document.getElementById("sele3").disabled=true; } function func3() { document.getElementById("sele1").style.display="none"; document.getElementById("sele1").disabled=true; document.getElementById("sele2").style.display="none"; document.getElementById("sele2").disabled=true; document.getElementById("sele3").style.display="inline"; document.getElementById("sele3").disabled=false; } </script> ■CGI(HTML)側 <form action="xxx"> <table border=0 cellpadding=5 cellspacing=2 width=500> <p>発送先が2箇所以上の場合はこちらから選択ください。 <input type="radio" value="1" onclick="func1('block')" />1箇所</label> <input type="radio" value="2" onclick="func2('none')" />2箇所</label> <input type="radio" value="3" onclick="func3('none')" />5箇所</label> </p> </table> <table id="sele1"> </table> <table id="sele2"> </table> <table id="sele3"> </table> </form> table内容は省略しています。 説明が下手ですがどうかご教授ください。宜しくお願いします。

  • Javascript 計算後の3桁区切り

    ホームページ用見積もりフォームをJavascriptで自動計算 縦に長いページで一番下に計算結果を表示 ページをスクロールしても、何時でも計算結果が見られるように、別のウィンドウ(レイヤー)でページ内に表示。 以上までは出来ました。 最後に計算結果を3桁区切りで表示させたいのですが、上手く出来ません。 お知恵をお貸しくださいませ。 Javascriptは外部参照しております。 3桁区切りのJavascriptを外部参照している同一のページに記入した方が良いか、別参照の方が良いかも教えていただければ幸いです。 以下がJavascriptのコードになります。 function keisan(){ // 設定開始 var tax = 5; // 消費税率 // 商品1 var price1 = document.form1.goods1.options[document.form1.goods1.selectedIndex].value; // 商品2 var price2 = document.form1.goods2.options[document.form1.goods2.selectedIndex].value; // 商品3 var price3 = document.form1.goods3.options[document.form1.goods3.selectedIndex].value; // 合計を計算 var total1 = parseInt(price1) + parseInt(price2) + parseInt(price3) ; // 設定終了 document.form1.field_total1.value = total1; // 合計を表示 var tax2 = Math.round((total1 * tax) / 100); document.form1.field_tax.value = tax2; // 消費税を表示 document.form1.field_total2.value = total1 + tax2; // 税込合計を表示 //右の窓に表示する金額 document.getElementById("display_account_amount").innerHTML = total1; document.getElementById("display_account_tax").innerHTML = tax2; document.getElementById("display_account_all").innerHTML = total1 + tax2; }

  • チェックボックスの連動でJavaScriptの記述を短くしたい。

    【あ】、【い】という項目があり、それぞれの項目内にA、Bというチェック項目があります。 【あ】項目のAにチェックを入れると【い】のAにもチェックが入るように作りました。 以下のソースでもなんとか動くのですが、【あ】、【い】という項目が増える事とA、Bというチェック項目が増えることが判り、JavaScriptのソースを少しでも短くしたいのですが、なにか好い方法がございましたらお教え頂ければ幸です。 /************参考ソースです*****************/ <html> <head> <title>無題ドキュメント</title> <script> function check_a(){ if(document.form.a.checked==true) { document.form.a.checked=true; document.form.b.checked=false; document.form.aa.checked=true; document.form.bb.checked=false; } } function check_b(){ if(document.form.b.checked==true) { document.form.a.checked=false; document.form.b.checked=true; document.form.aa.checked=false; document.form.bb.checked=true; } } function check_aa(){ if(document.form.aa.checked==true) { document.form.a.checked=true; document.form.b.checked=false; document.form.aa.checked=true; document.form.bb.checked=false; } } function check_bb(){ if(document.form.bb.checked==true) { document.form.a.checked=false; document.form.b.checked=true; document.form.aa.checked=false; document.form.bb.checked=true; } } </script> </head> <body> <form name="form"> 項目【あ】 <input type="checkbox" name="a" onclick="check_a()"> A<BR> <input type="checkbox" name="b" onclick="check_b()"> B<BR> <br /> 項目【い】 <input type="checkbox" name="aa" onclick="check_aa()"> A<BR> <input type="checkbox" name="bb" onclick="check_bb()"> B<BR> <br /> </form> </body> </html> /*************************/ 何卒、宜しくお願い申上げます。m(_ _)m