2017-05-05 17 views
0

入力値をデフォルト値で埋める塗りつぶしボタンを作成しようとしています。塗りつぶしボタンをクリックすると、デフォルトが2秒間表示されてから消えます。どのように私は情報をそれ自体をクリアすることなく滞在することができます。なぜonclickイベントの直後に入力ボックスがクリアされる


var enter, replace, FirstName, Telephone, email, BithDate, LastName, ZipCode, SS, Cash; 

window.onload = function() { 
    //calls the functions when buttons clicked 
    replace = document.getElementById("fill"); 
    replace.addEventListener("click", filler); 

    enter = document.getElementById("enter"); 
    enter.addEventListener("click", calculate); 
    var clear = document.getElementById("clear"); 
    clear.addEventListener("click", clear); 
} 

function filler() { 
    //list the default values to fill when the fill button is clicked 
    FirstName = document.getElementById("FirstName").value = "Jane"; 
    Telephone = document.getElementById("tel").value = "888-777-9999"; 
    email = document.getElementById("email").value = "[email protected]"; 
    BithDate = document.getElementById("birth").value = "2017"; 
    LastName = document.getElementById("LastName").value = "Doe"; 
    ZipCode = document.getElementById("zip").value = "12345"; 
    SS = document.getElementById("SocSec").value = "123-45-6789"; 
    Cash = document.getElementById("income").value = "123456"; 
} 

function clear() { 
    //clears the form and resets it to the default 
    document.getElementById("form").reset(); 
} 
+0

plunkerやjsfiddleなどの場所にサンプルを投稿すると、htmlを追加してください。 – Ivan

+0

'filler()'関数が機能していますか?変数宣言が間違っていました** '' message ":"キャッチされていないTypeError:nullのプロパティ 'value'を設定できません "、** ** – prasanth

+0

また計算機能がありません。 HTMLを投稿することも役に立ちます。 –

答えて

0

あなたは「クリア」グローバルクリア機能をシャドウ、そうclear.addEventListenerた(「クリック」、クリア)クリアボタンのためのあなたのローカル変数の名前。動作しません。ローカル変数の名前をclearBtnのように変更してみてください。

関連する問題