WordPress.org

Ready to get started?Download WordPress

Forums

javascript within widget form (1 post)

  1. Koff
    Member
    Posted 3 years ago #

    Hi,
    I am trying to add a widget.
    The widgets form should be dynamic.
    for example Email filed is shown just if a checkbox is selected.

    From some reason i cant get it to work.

    Here is the code:

    <input id="checkme" type="checkbox" />
    <div id="extra">
    <label for="email">Email Address:</label>
    <input id="email" type="text" />
    </div>

    and the javascipt:

    <script type="text/javascript"> 
    
    	$(document).ready(function(){
    		//Hide div w/id extra
    	   $("#extra").css("display","none");
    		// Add onclick handler to checkbox w/id checkme
    	   $("#checkme").click(function(){
    		// If checked
    		if ($("#checkme").is(":checked"))
    		{
    			//show the hidden div
    			$("#extra").show("fast");
    		}
    		else
    		{
    			//otherwise, hide it
    			$("#extra").hide("fast");
    		}
    	  });
    
    		});
    	 </script>

Topic Closed

This topic has been closed to new replies.

About this Topic