How To Show And Hide Input Fields Based On Radio Button Selection

前端 未结 8 1224

Here is the code to show input fields depending on radio selection like:

SCRIPT



        
8条回答
  •  甜味超标
    2020-11-29 02:04

    Using the visibility property only affects the visibility of the elements on the page; they will still be there in the page layout. To completely remove the elements from the page, use the display property.

    display:none // for hiding
    display:block // for showing
    

    Make sure to change your css file to use display instead of visibility too.

    As for the javascript (this is not jQuery), make sure you hide the options by default when the page loads:

    
    

    If you haven't done so already, I would recommend taking a look at jQuery. jQuery code is much clearer and easier to write and understand.

    http://www.w3schools.com/jquery/default.asp

提交回复
热议问题