javascript - How to make a button visible by clicking another button? - Stack Overflow

How can I make the button save visible when I click the edit button? This is my code so far, but it hap

How can I make the button save visible when I click the edit button? This is my code so far, but it happends nothing. I'm working in a jsp

   <INPUT TYPE="BUTTON" VALUE="Edit" ONCLICK="btnEdit()" class="styled-button-2">
    <INPUT TYPE="BUTTON" VALUE="Save" ONCLICK="btnSave()" class="styled-button-2" style="visibility:hidden;" id="save">

    <SCRIPT LANGUAGE="JavaScript">
        function btnEdit()
        {
            {document.getElementsById("save").style.visibility="visible";}

        }    
     </script>

How can I make the button save visible when I click the edit button? This is my code so far, but it happends nothing. I'm working in a jsp

   <INPUT TYPE="BUTTON" VALUE="Edit" ONCLICK="btnEdit()" class="styled-button-2">
    <INPUT TYPE="BUTTON" VALUE="Save" ONCLICK="btnSave()" class="styled-button-2" style="visibility:hidden;" id="save">

    <SCRIPT LANGUAGE="JavaScript">
        function btnEdit()
        {
            {document.getElementsById("save").style.visibility="visible";}

        }    
     </script>
Share edited Oct 9, 2015 at 9:41 Aniket Kulkarni 13k9 gold badges69 silver badges92 bronze badges asked Mar 2, 2015 at 16:12 wohooooowohooooo 231 gold badge1 silver badge7 bronze badges 3
  • 3 getElementById not getElementsById. – Ram Commented Mar 2, 2015 at 16:15
  • you also can get rid of the extra "block" created with the second level braces – n1kkou Commented Mar 2, 2015 at 16:18
  • please, read the javascript conventions... your code is horrible – Tommaso Bertoni Commented Mar 2, 2015 at 16:19
Add a ment  | 

4 Answers 4

Reset to default 2

DEMO

It is considered bad practice to add onclick in your html, and you miss-spelled a method. You should equally avoid adding your css in your html as well.

HTML:

<INPUT TYPE="BUTTON" VALUE="Edit" class="styled-button-2" id="edit">
<INPUT TYPE="BUTTON" VALUE="Save" class="styled-button-2" id="save">

JS:

var edit = document.getElementById("edit");
var save = document.getElementById("save");

edit.onclick = function() {
    save.style.visibility = "visible";

}

CSS:

#save {
    visibility: "hidden";
}

Must be a long day.

You have a misspelling.

Not right

document.getElementsById

Right Way

document.getElementById
document.getElementById("save").style.visibility="visible";

use getElementById not getElementsById

Probably a simple error, but you wrote getElementsById not getElementById, which meant you were trying to get more than one element, when infact you only need to get the "save" button.

<SCRIPT LANGUAGE="JavaScript">
    function btnEdit()
    {
        {document.getElementById("save").style.visibility="visible";}

    }    
 </script>

Side note: You may want to tidy your code:

<SCRIPT LANGUAGE="JavaScript">
    function btnEdit()
    {
        document.getElementById("save").style.visibility="visible";
    }    
</script>

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744925608a4601415.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信