0

入力要素の1つを変更してCookieのコンテンツを追加し、このコンテンツを他の入力要素とともに電子メールで送信する送信フォームを作成しようとしています。value 属性へのアクセスや子要素の追加など、さまざまな方法を試しましたが、firefox を使用して役に立ちませんでした。

HTML

<form method="GET" action="mailto:davidflynn12@hotmail.com">
    <input type="hidden" name="subject" value="javascript:GetTotal()">
    <input type="hidden" name="body" value="test">
    <input type="submit" value="Send Email">
</form>
<form id="form1" action="mailto:admin@example.com" enctype="text/plain"
method="post">
    <a href="javascript:addOption()">Add Details </a>
    <p>Name:
        <input name="Name" type="text" id="Name" size="40" value=javascript:GetTotal()>
    </p>
    <p>E-mail address:
        <input name="E-mail" type="text" id="E-mail" size="40">
    </p>
    <p>Comment:</p>
    <p>
        <textarea name="Comment" cols="55" rows="5" id="Comment"></textarea>
    </p>
    <p>
        <input type="submit" name="Submit" value="Submit">
    </p>
</form>

JS

function GetTotal() {
    // Get the individual cookies, by splitting the cookie string
    // Individual cookies is now an array of all the name=value pairs
    var individualCookies = document.cookie.split(';');
    var temp3 = 0;
    //document.write("<p class = 'special_p'>");
    for (var i = 0; i < individualCookies.length; i++) {
        // Loop through each of the cookies, and split them into
        // their name and value, as separate elements in the array
        var oneCookie = individualCookies[i].split("=");
        var name = oneCookie[0];
        var value = oneCookie[1];


        // This is standard code for removing excess white space
        name = name.replace(/^\s+|\s+$/g, '');
        //document.write("<ul>");
        document.write("<ul>");
        if (name == 'History of Boxing') {
            var temp = 7;
            var temp2 = temp * value;
            document.write("<li class = 'special_p'>" + name + " By David
                                Flynn. No. of Copies: " + value + ".Total cost
                                =" + temp2 + "Euros</li>");
        } else if (name == 'Future of Boxing') {
            var temp = 8;
            var temp2 = temp * value;
            document.write("<li class = 'special_p'>" + name + " By
                                    David Flynn. No. of Copies: " + value + ".Total cost =
                                    " + temp2 + "Euros</li>");
        } else if (name == 'History of TaeKwondo') {
            var temp = 9;
            var temp2 = temp * value;
            document.write("<li class =
                                                'special_p'>" + name + " By David Flynn. No.
                                                of Copies: " + value + ".Total cost =
                                                " + temp2 + "Euros</li>");

        } else if (name == 'Future of TaeKwondo') {
            var temp = 10;
            var temp2 = temp * value;
            document.write("<li class =
                                                'special_p'>" + name + " By David Flynn. No.
                                                of Copies: " + value + ".Total cost =
                                                " + temp2 + "Euros</li>");

        }
        document.write("</ul>");
        temp3 += temp2;
        //document.write("Grand total = "+temp3"):
    }
    document.write("<p class = 'special_p'>Total bill is
                                " + temp3 + " Euros</p>");
    //document.write("</p>");
}
4

2 に答える 2

1

フォームは必要ありません。ここで私のフィドルをチェックしてください。

HTML

<input type="button" value="Send Email" onclick="getTotal()"/>

<strong>JS

function getTotal() {
    var mail = 'mailto:davidflynn12@hotmail.com';
    mail = mail + '?subject=Subject';
    mail = mail + '&body=Body';
    location.href = mail;
};
于 2012-06-01T20:08:12.493 に答える
0

JavaScript では、次のようにします。

document.getElementById("Name").value = cookieValue;

ページが読み込まれたとき、つまり

HTML:

<body onload="setNameValue()">

JavaScript

function setNameValue(){
    document.getElementById("Name").value = cookieValue;
}

それが役立つことを願っています!

于 2012-06-01T19:56:51.230 に答える