简体   繁体   中英

Display a pop-up on radio button click

Please let me know how to open a pop-up on click of a radio button using JQuery. Currently Im using a the following code for a radio button using Spring MVC and JSTL

<label class = "">
 <form:radiobutton path = "" value = "" onchange= ""/>
<label class = "" style = ""> <spring:message code ="" /></label>
</label>

Many Thanks

I am assuming you mean a new window by pop-up ?

The following code will open a new window with the URL when the status of the radio button changes. You can use click if you like...

$("#pop").change(function() {
    window.open("http://www.google.com");
});

<input type="radio" id="pop" value="yes">

JSFiddle Example

I hope this will solve your problem.

onchange= "window.open("http://www.stackoverflow.com",width=200,height=100); "/>

EDIT1: Removing the hide class does the trick.

jQuery:

$(document).ready(function () {
    $('input[type="radio"]').click(function () {       
                $('#r').removeClass("hide");
    });
});

HTML:

<input type='radio'>SO
<div id="r" selectOption="#" class="modal hide" tabindex="-1" role="dialog" style=" background-color:#ccc; height: 100px;width: 350px"></div>

EDIT2:

If you check my html code, you will see an id for div named as "r" (unique selector) and class name "hide" prevent the div to be displayed. Therefore the div is hidden.

When the radio button is click, using removeClass we're removing the class "hide" this make the div visible.

Check this JSFiddle

Hope you understand.

you mean like this?

HTML

<input type='radio' id='myRadio'>Radio button

JQuery

$(document).ready(function()
{
    $('#myRadio').click(function()
    {
        alert("Clicked");
    });
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM