inputImageObject.formActionプロパティ

inputImageObject.formActionは、画像を使う送信ボタン(type属性がimageであるinput要素)のformAction属性の値を取得、もしくは、設定するプロパティ。

formAction属性には、フォーム内容送信先ドキュメントのURLを指定することができる。画像を使う送信ボタンのformAction属性を指定した場合、画像を使う送信ボタンが属するフォーム(form要素)のaction属性よりも優先される。

構文

取得

var $formAction = $inputElementReference.formAction;

戻り値

画像を使う送信ボタン(type属性がimageであるinput要素)のformAction属性の値。

設定

$inputElementReference.formAction = "URL";
URL
送信先ドキュメントのURLを指定する。

サンプル

画像を使う送信ボタンのformAction属性の値:

【サンプルフォーム】
入力欄:

サンプルの動作について

  • 「A」ボタンをクリックすると、画像を使う送信ボタンのformAction属性値を「http://alphasis.info/2014/01/javascript-dom-input-image-formAction/」にする。「画像を使う送信ボタンのformAction属性の値:」の右横に「http://alphasis.info/2014/01/javascript-dom-input-image-formAction/」と表示する。
  • 「B」ボタンをクリックすると、画像を使う送信ボタンのformAction属性値を「http://alphasis.info/2014/01/javascript-dom-input-image-width/」にする。「画像を使う送信ボタンのformAction属性の値:」の右横に「http://alphasis.info/2014/01/javascript-dom-input-image-width/」と表示する。
  • 「画像を使う送信ボタン」をクリックすると、画像内におけるクリックした位置の座標と、入力欄の入力内容を、formAction属性値のURLに送信する。座標は、画像の左上端を原点とする。

サンプルのソースコード

JavaScript

<script type="text/javascript">
function setFormAction( $formAction ) {
    var $elementReference = document.getElementById( "sample" );
    $elementReference.formAction = $formAction;
    var $formAction = $elementReference.formAction;
    document.getElementById( "sampleOutputA" ).innerHTML = $formAction;
}
</script>

HTML

<p>
    <button onclick="setFormAction('http://alphasis.info/2014/01/javascript-dom-input-image-formAction/');"></button>
    <button onclick="setFormAction('http://alphasis.info/2014/01/javascript-dom-input-image-width/');"></button>
</p>
<p>画像を使う送信ボタンのformAction属性の値:<span id="sampleOutputA"></span></p>
<form id="sampleForm" method="get" action="http://alphasis.info/2014/01/javascript-dom-input-image-width/" target="_blank">
    【サンプルフォーム】
    <br />
    入力欄:<input type="text" name="sampleName" value="sampleValue">
    <br />
    <input type="image" src="http://alphasis.info/wp-content/uploads/2013/12/sampleImageButton.png" alt="送信" id="sample" formAction="http://alphasis.info/2014/01/javascript-dom-input-image-formAction/">
</form>

スポンサード リンク

カテゴリー: DOM, input type=image オブジェクト, JavaScript, リファレンス パーマリンク