プロが教えるわが家の防犯対策術!

(1)index.htmlの記述の中に、たとえば
<a href="form.html?/info_mail@ff5.ocn8.ne.jp">自動返信テスト</a>と書きます。

(2)このリンクをクリックしてform.htmlを表示します。
このページのtableタグの中にあるinputタグに最初から格納させる方法
をご教授いただけないでしょうか?

form.htmlのソースは、

<html>
<head>
<title>登録</title>

<script language="JavaScript">
<!--
var STR = location.href;
var STR1 = STR.split("?");

if (STR1.length > 1){
var STR2 = STR1[1].split("/");
STR2.shift();

for (i in STR2){
switch ( STR2[i] ) {
case "":
break;
case "":
break;
case "":
break;
default:
break;
}
document.getElementById("eml").value=STR2[i];

}
}
//-->
</script>

</head>
<body>
<font color="#f35e3c">登録</font><br>
<form action="./cgi-bin/testhogehoge2008.cgi" method="post">
アドレス<br>
<input name="email" type="text" size="20" maxlength="50" id="eml" />
<input name="email" type="hidden" size="20" maxlength="50" id="eml" /><br>
<input type=submit value="確認">
</form>
</body>
</html>



です。



まったくわかりません。困っています。
よろしくお願いいたします。

A 回答 (3件)

すみません。


hashではなくsearchでした。

1+location.search.indexOf('?') の方法ですが、
古いブラウザを考えてのことですので、モダンブラウザだけならlocation.search.substring(1)で大丈夫です。
    • good
    • 0

getElementByIdを使う場合、対象を読み込んだ後でないと見つからずにエラーになります。


(scriptを</form>の後にでも書けばいいでしょう。)

なお、location.searchを参照すればsubstringで抜き出せます。
document.getElementById("eml").value =
location.search.substring(1);

http://www.tohoho-web.com/js/location.htm
    • good
    • 0

hrefではなくhashを使用してください。


あと、JavaScriptのカテゴリーで聞いた方がより適切な回答が得られると思います。


//splitしなくても、以下のようにすると1行で取れます。
var hash=location.hash.substring(1+location.hash.indexOf('?'));

alert(hash);
    • good
    • 0

お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!