• ベストアンサー

フォームの送信ボタンを画像にしたい

<div style="float:left; margin-left:5px; margin-top:4px;"> <form id="form1" name="form1" method="post" action="test"> <input type="hidden" name="sample" value="test"> <span onclick="submit()" id="sample2" style="cursor:pointer;"> <img src="img.jpg" alt="sample"></span> </form> </div> html内に上記のように記述し、 フォームの送信ボタンを作成いたしました。 IEでは問題なく動作したのですが、 ファイヤーフォックスでは動作しませんでした。 調べたところ、documentを省略せずに記述すると動作するとなっていたので、下記のように書き換えました。 <div style="float:left; margin-left:5px; margin-top:4px;"> <form id="form1" name="form1" method="post" action="test"> <input type="hidden" name="sample" value="test"> <span onclick="document.form1.submit()" id="sample2" style="cursor:pointer;"> <img src="img.jpg" alt="sample"></span> </form> </div> そうすると今度はIEでもファイヤーフォックスでも動作しなくなりました。 どこか記述が間違っているのかもわからず、悩んでいます。 解決策や修正箇所等教えていただきたく思います。 ちなみに、やりたいことは 「フォームの送信ボタンをテキストリンク、もしくは画像リンクのように見せたい」 ということだけです。 よろしくお願いいたします。

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

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

単純にtype="image"ではだめなの? <form> <input type="hidden" name="sample" value="test"> <input type="image" src="1.jpg"> </form> どうしてもjavascriptでというならこう? <form id="form1"> <input type="hidden" name="sample" value="test"> <img src="1.jpg" onclick="document.getElementById('form1').submit()"> </form>

hukazuo
質問者

お礼

ありがとうございました。 思いのほか簡単にできてびっくりです^^;

その他の回答 (3)

  • steel_gray
  • ベストアンサー率66% (1052/1578)
回答No.4

#3です。 記述ミス・・・ ×同じくtype="img"で。 ○同じくtype="image"で。 ついでに、文字の大きさもまわりのテキストに合わせるならスタイルに font-size:100%; を追加。

  • steel_gray
  • ベストアンサー率66% (1052/1578)
回答No.3

>フォームの送信ボタンをテキストリンク、もしくは画像リンクのように見せたい submitのボタン的なスタイルを止めたいという事ならCSSで。 <style type="text/css"> .submit_botton { border:none;/*枠線なし*/ background-color:transparent;/*背景透明*/ text-decoration:underline;/*下線*/ } </style> <input type="submit" value="送信" class="submit_botton"> 画像にするなら#1さんと同じくtype="img"で。

hukazuo
質問者

お礼

ありがとうございました。 cssでもできるのですね。 今回はtype=imageで行いました。

回答No.2

一部のブラウザはsubmitボタンがないformは送信できないようになってるので、 <input type="image">を使わないのであれば、 <input type="submit" value="送信" style="display:none;"> というのを書いておくといいかもしれません。 未検証です。

hukazuo
質問者

お礼

ありがとうございました。 この方法だとボタン自体が消えてしまったので 別の方法にしました。

関連するQ&A

  • ツリー型の目次作成

    ツリー型の目次を作成しているのですが、IEでは動作するのですが、ネスケではエラーになってしまいます。 うまく動作させる方法はないでしょうか? 下記がソースです。 <html> <head> <title>目次</title> <style type="text/css"> div.h_ {margin-left:0px;margin-top:6px;} div.h {margin-left:28px;margin-top:6px;} div.sy_ {margin-left:28px;margin-top:6px;} div.sy {margin-left:56px;margin-top:6px;} div.st_ {margin-left:56px;margin-top:6px;} div.st {margin-left:84px;margin-top:6px;} div.k_ {margin-left:84px;margin-top:6px;} div.k {margin-left:112px;margin-top:6px;} } </style> <script language="JavaScript"> <!--// function displayMokuji(obj, img) { alert("displayMokuji"); if (!obj || !img) alert("bbb"); return; } if (obj.style.display == "none") { obj.style.display =""; img.src ="./open.gif"; } else { obj.style.display ="none"; img.src = "./close.gif"; } return; } //--> </script> </head> <body text="#000000" link="#0000ff" alink="#ff0000" vlink="#0000ff"> <div class="h_"> <a onclick="javascript:displayMokuji(hi0100000000, ii01000000);" href="#"> <img id="ii01000000" src="./close.gif" border="0"></a>  <b>第1編 </b> </div> <div id="bbb" style="display:none"> <div class="sy"> <b>第1章</b> </div> <div class="sy"> <b>第2章</b> </div> </div> </body> </html>

  • CSSについて 入力フォームの上下揃い

    CSSについて 入力フォームの上下揃い sample.css @CHARSET "windows-31j"; html,body,div,span,h1,h2,h3,h4,h5,h6{margin:0; padding:0; font-size:100%} html { height:100%; } body { height:100%; } body > #container { height: auto; z-index:0; } #container{ width:780px; margin-top:auto; margin-left:auto; margin-right:auto; margin-bottom:auto; position:relative; min-height:100%; border:1px solid #999; } #header{ margin: 0; padding: 0px 0px 0px 0px; width: 100%; height: 100px; background-color:#4682B4; z-index:1; } #main{ padding:auto; width:100%; backgruond-color:#87CEEB; z-index:1; } #footer{ position:absolute; bottom:0px; width: 100%; height: 100px; background-color:#4682B4; z-index:1; } index.html <div id="container"> <div id="header"></div> <div id="main"> <div class="vartical-align"> <form action=""> <input type="text" name="id"> <input type="password" name="pas"> </form> </div> </div> <div id="footer"></div> </div> 上記の用なCSSにて入力フォーム等を、id=main内にて上下中央揃えにしたいのですが どうした良いでしょう?

  • css フォームのプルボタンを使う場合

    cssでselect(プルダウンメニュー)を定義すると、 その後のフォーム(例えばテキストフィールド)のレイアウトが崩れます。 お詳しい方、ご教授いただければ幸いです。 ======================================= html側の記述です ======================================= <form accept-charset="UTF-8" action="/mmm" > <div style="margin:0;padding:0;display:inline"></div> <div class="field"> <label for="vvv">氏名</label> <input id="vvv_name" name="vvv[name]" size="30" type="text"> </div> <div class="field"> <label for="xxx">好きな果物</label> <select id="xxx" name="site[ftp_id]"><option selected="selected" value=""></option> <option value="1">りんご</option> <option value="2">さくらんぼ</option></select> </div> <div class="field"> <!--#ここのレイアウトが崩れます--> <label for="yyy">好きな動物</label> <input id="yyy" name="yyy[yyy]" size="30" type="text"> </div> </form> ======================================= cssの記述です ======================================= * { margin: 0; padding: 0; } .field { width:500px;} .field label { width:230px; float:left; color:#FFFFFF; background-color:#001207; display:block; height: 2em; line-height :2em; margin-top:10px; } .field input { width:200px; float:left; color:#FFFFFF; margin-top:10px; height: 2em; } .field select { width:200px; float:left; color:#FFFFFF; margin-top:10px; height: 2em; } どうぞよろしくお願い致します。

    • 締切済み
    • CSS
  • 4枚の画像を均等間隔で一列に並べる

    4枚の画像を一列に並べようと思います。 4枚に与えられたスペースは550pxです。画像の下のコンテンツも550pxを基準に配置するので、4枚のうちの両側の2枚は550pxの両端に配置しようと思います。 この趣旨でコーディングしたのが下記URLです。 http://makoji.web.fc2.com/test/test_18/test.html 他の画像を margin-right: 14px; とすると綺麗に並びました。ただ確認をとったのは最近のブラウザだけで、古いブラウザでどうなっているのか分かりません。過去の例でうまく並んだと思ったらIE6.0で4枚目が2列目に改行されてしまっていたことがあります。 そこでmarginをブラウザに自動割り振りさせることが出来ないものかと思案するのですが・・・ とりあえず右端の画像を右端に寄せるために margin-right: 0px; margin-left: auto; としてみましたがダメでした。でも width: 125px; もしくは float: right; を挿入すれば解決できます。 しかしながら真ん中の2枚をどうすれば均等に配置できるかが分かりません。 この場合、古いブラウザを試せる環境を全部揃えて片っ端からチェックを入れるしかないのでしょうか。 -------------------------------------------------------------------------------- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=Shift_JIS"> <style type="text/css"> <!-- * { font-size: 14px; font-wight: 100; color: #000000; } .wrap { margin: 0px auto; width: 700px; } .logo { border: solid 1px #FF0099; } .main { padding-top: 15px; padding-bottom: 15px; border: solid 1px #FF0099; } .main img { margin-right: 2px; float:left; display: block; } .menu { float: left; margin-top: 0px; margin-left: 10px; padding-left: 0px; } .menu li { margin-bottom: 2px; padding-top: 5px; padding-bottom: 5px; padding-left: 10px; width: 100px; list-style-type: none; background-color: #FFCCFF; } .list span { color: #FF0099; } .menu a:link { color: #FF0099; } .menu a:visited { color: #FF0099; } .menu a:active { color: #FF0099; } .menu a:hover { color: #FF0099; } .clear { clear: both; } /* インデックス */ .index_body { margin-top: 15px; padding-left: 133px; } .sample { margin-bottom: 10px; width: 550px; text-align:center; background-color: yellow; } .sample a { text-decoration: none; } .sample img { border: solid 1px #FF0099; float: none; } .sample .left { float: left; margin: auto auto auto 0px; text-align: center; } .sample .middle { float: left; margin: auto; text-align: center; } .sample .right { margin-right: 0px; margin-left: auto; text-align: center; } --> </style> </head> <body> <div class="wrap"> <div class="logo"> <img src="dot_999999.gif" width="698" height="120"> </div><!-- end of "logo"--> <div class="main"> <ul class="menu"> <li>ああ</li> </ul><!-- end of menu --> <div class="index_body"> <div class="sample"> <div class="left"> <img src="dot_999999.gif" width="123" height="170" alt="ああああ"> <div>aaaaa</div> </div><!-- end of "left" --> <div class="middle"> <img src="dot_999999.gif" width="123" height="170" alt="ああああ"> <div>aaaaa</div> </div><!-- end of 1of"middle" --> <div class="middle"> <img src="dot_999999.gif" width="123" height="170" alt="ああああ"> <div>aaaaa</div> </div><!-- end of 2of"middle" --> <div class="right"> <img src="dot_999999.gif" width="123" height="170" alt="ああああ"> <div>aaaaa</div> </div><!-- end of "right" --> </div><!-- end of "sample" --> <div><img src="dot_999999.gif" width="550" height="450" alt="" /></div> <div class="clear"></div> </div><!-- end of "index_body" --> </div><!-- end of "main" --> </div><!-- end of "wrap" --> </body> </html>

  • 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") { } を消すと表示はできるのですが・・・

  • float: leftで横に並べたら、サファリだけ

    float: leftで横に並べたら、サファリだけ隙間が空いてしまいます。 IEやファイヤーフォックスではピッタリ表示できています。 問題の箇所は以下です。 <div style="float: left;"> <p style="position: relative;"> <img src="./img/img-001.png" width="240" height="150" /> <br /> <span style="font-size: 12px; padding: 2px 5px 2px 5px; position: absolute; top: 130px; left: 0px; width: 230px; height: 16px; color: white ; background-color: black; opacity: 0.6;">テストテスト1</span> </p> </div> <div style="float: left;"> <p style="position: relative;"> <img src="./img/img-002.png" width="240" height="150" /> <br /> <span style="font-size: 12px; padding: 2px 5px 2px 5px; position: absolute; top: 130px; left: 0px; width: 230px; height: 16px; color: white ; background-color: black; opacity: 0.6;">テストテスト2</span> </p> </div> <div style="float: left;"> <p style="position: relative;"> <img src="./img/img-003.png" width="240" height="150" /> <br /> <span style="font-size: 12px; padding: 2px 5px 2px 5px; position: absolute; top: 130px; left: 0px; width: 230px; height: 16px; color: white ; background-color: black; opacity: 0.6;">テストテスト3</span> </p> </div> どうすればサファリの隙間を消せるでしょうか?

    • ベストアンサー
    • HTML
  • 画像表示の際空っぽの項目を非表示にするには、、

    画像を含んだ検索システムについてご相談があります。 画像の部分で、データが空っぽの場合検索結果の更に詳細ページにて非表示にする条件分岐についてつまづいています。 レコードに画像データがある場合は検索結果にて表示し、データが空っぽの場合は非表示にするというものです。 以下に詳細ページ(検索結果一覧から詳細ページに進んだページ)の該当箇所のコードを記載します。 if文を使うのだろうというのはわかるのですが、どう書いていいかわからないでいます。 アドバイスいただけないでしょうか? よろしくお願いします。 ~省略~ <?php $debug = false; //DB Connect $url = "***********"; $user = "**********"; $pass = "********"; $db = "********"; $link = mysql_connect($url,$user,$pass) or die("No Connected"); $sdb = mysql_select_db($db,$link) or die("No Selected"); if($debug) echo_r($_POST); mysql_set_charset('utf8'); if($_SERVER["REQUEST_METHOD"] != "POST") { echo "Error: invalid method"; exit(); } $id = $_POST['key']; $query = "SELECT * FROM shops where id='$id'"; $result = mysql_query($query) or die($query . '<br />' . mysql_error() . '<hr />'); $num_rows = mysql_num_rows($result); ?> <div class="row "> <div id="contents" class="clearfix"> <div class="span8"> <h2 class="f2"><b>■店舗詳細</b></h2> <?php while($row = mysql_fetch_assoc($result)): ?> <div class="row-fluid result-table" style="background-color:white;"> <div class="row-fluid"> <?php echo '<img src="get_image1.php?id=' . $row['id'] . '" style="width:100%;">'; ?> </div> <div class="span4 mini-img"style="margin-left:-1px;"><p class="thumb"><a><?php echo '<img src="get_image2.php?id=' . $row['id'] . '" >' ?></a></p> </div> <div class="span4 mini-img"style="margin-left:-1px;"><p class="thumb"><a ><?php echo '<img src="get_image3.php?id=' . $row['id'] . '" >' ?></a></p> </div> <div class="span4 mini-img"style="margin-left:-1px;"><p class="thumb"><a ><?php echo '<img src="get_image4.php?id=' . $row['id'] . '" >' ?></a></p> </div> <div class="span4 mini-img"style="margin-left:-1px;"><p class="thumb"><a ><?php echo '<img src="get_image5.php?id=' . $row['id'] . '" >' ?></a></p> </div> <div class="span4 mini-img"style="margin-left:-1px;"><p class="thumb"><a ><?php echo '<img src="get_image6.php?id=' . $row['id'] . '" >' ?></a></p> </div> <div class="span4 mini-img"style="margin-left:-1px;"><p class="thumb"><a ><?php echo '<img src="get_image7.php?id=' . $row['id'] . '" >' ?></a></p> </div> ~以下省略~

    • ベストアンサー
    • PHP
  • borderの範囲

    cssコーディングに関しての質問です。 現在以下のようなスタイルとHTMLを組んでいます。 ==css============ #style1 {  width:500px;  padding: 15px 0 0 15px;  border-left:1px solid #ccc;  border-top: 1px solid #ccc; } #style1 p {  margin:0;  padding:0; } .style2 {  float:right;  clear:both;  margin:0 0 20px 30px; } .style2 img{  margin:0;  padding:0; } ==html============ <body>  <div id="style1">   <div class="style2"><img src="sample.jpg" width="200" height="200"></div>   <div class="style2"><img src="sample.jpg" width="200" height="200"></div>   <p>サンプルサンプルサンプルサンプルサンプルサンプルサンプルサンプルサンプルサンプルサンプルサンプルサンプルサンプルサンプルサンプルサンプルサンプルサンプルサンプルサンプルサンプルサンプルサンプルサンプルサンプルサンプルサンプルサンプルサンプルサンプルサンプルサンプルサンプルサンプルサンプルサンプルサンプルサンプルサンプルサンプルサンプルサンプルサンプルサンプル</p>  </div> </body> イメージをfloat:right;に指定し、 縦並びにしたいので、clear:both;を入れた所、 border-left:1px solid #ccc;のborderが文字までは表示されるのですが、 画像の延長上は無くなって表示されてしまいます。 右に画像を配置し borderを伸ばしたい時はどのようにすればよいのでしょうか? よろしくお願いします!

    • ベストアンサー
    • HTML
  • スタイルシートのレイヤーに乗せた画像を動的に表示する方法

    <div id="test" style="position=absolute; top=400px; left=200px; z-index=10;"><img src="gazou.gif"></div> 上記を動的に表示するために以下の方法を考えました var element = document.createElement('div'); element.id = "test"; element.style = "position=absolute; top=400px; left=200px; z-index=10;"; element.innerHTML = '<img src="gazou.gif">'; var objBody = document.getElementsByTagName("body").item(0); objBody.appendChild(element); しかしこれだと、element.style = "position=absolute; top=400px; left=200px; z-index=10;"; の部分がまずいらしく動作しません。 どのようにすればよいでしょうか。 よろしくお願いします。

  • <a>の中のimgの一部分だけを見せたい

    imgの拡大切り取りを以下の様にしました。 <div style="position: relative; width: 240; height: 240; overflow: hidden;"> <img src="imgA.jpg" style="width: 3600; height: 4800; margin-left: -2936; margin-top: -3272;"> </div> この要領で、<a>の中に入れるjpgを切り取り拡大した物にしたいです。 しかし、<a>の中に<div>を入れるとIEは動作が変になります。 どうしたらよいでしょうか? 具体的には以下のようなソースでして、 <html> <head> <meta http-equiv='Content-Type' content='text/html; charset=utf-8'/> <meta http-equiv='Content-Style-Type' content='text/css'> <style> img{ border: 0px; } #itmImg{ width: 240px; float: left; position: relative; } #itmImg img{ display:block; } #itmImg a span{ display: none; } #itmImg ul li a:hover{ position: static; } #itmImg a:hover span{ display:block; position:absolute; top:0; left:0; cursor: default; } #itmImg ul { margin: 0; padding: 0; } #itmImg li{ float:left; list-style:none; } </style> </head> <body> <div id="itmImg"> <div style="position: relative; width: 240; height: 240; overflow: hidden;"><img src="imgA.jpg" style="width: 3600; height: 4800; margin-left: -2936; margin-top: -3272;"></div> <ul> <li><a href="javascript:void(0);"><img src="imgB.jpg" width="80" height="80" alt=""><span><img src="imgB.jpg" width="240" height="240" alt=""></span></a></li> <li><a href="javascript:void(0);"><img src="imgC.jpg" width="80" height="80" alt=""><span><img src="imgC.jpg" width="240" height="240" alt=""></span></a></li> <li><a href="javascript:void(0);"><img src="imgD.jpg" width="80" height="80" alt=""><span><img src="imgD.jpg" width="240" height="240" alt=""></span></a></li> </ul> </div> </body> </html> 3つの<li>の中の<a>の中のimgを拡大縮小したいのです。 以上、宜しくお願いいたします。

    • ベストアンサー
    • CSS

専門家に質問してみよう