Redirecting With JavaScript If a Radiobox Is Checked

redirecting with javascript if a radiobox is checked

You can use required="required" in the fields and set the form action to the page you want to redirect.

<form action="processorari.php" method="POST">  <input type="radio" id="effettuato" name="sicep" value="Effettuato" required="required" />Effettuato <br/>  <input type="radio" id="noneffettuato" name="sicep" value="Non Effettuato" required="required" />Non Effettuato <br/>  <input class="button" type="submit" name="submit" value="Invia" button style="height:50px;width:150px"></form>

If radio box is checked go to link

http://jsfiddle.net/ryBs6/47/ - Update jsfiddle

$("input[type='radio']").on("click",function(){window.open($(this).attr("href"))})

anyway this would work , because if i right click and open link in new tab it works , but single click doesnt work, i dont know if this is disabled for security reasons or what !

http://jsfiddle.net/prollygeek/6vCdX/

<a href="http://www.google.com"><input type="radio" name="order" id="noi"  value="noi"></a>
<label for="noi">Most Recent</label>

Redirect browser based on radio button value

I would change the html just a bit to something like this:

<form>
<input type="radio" name="redirect" value="http://google.com"><span>Google</span><br>
<input type="radio" name="redirect" value="http://yahoo.com"><span>Yahoo</span><br>
<input type="radio" name="redirect" value="http://bing.com"><span>Bing</span>
</form>

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script>
$('input[type="radio"]').on('click', function() {
window.location = $(this).val();
});
</script>

I would also change to the .on() method since it simply makes a call to .on() anyways. The reason is that .click() simply makes a call to the .on() method creating one extra function call that isn't really necessary. Plus .on() is much more flexible!

redirect to different pages on selected radio button using button click

Try this

Html

<div id="mask">
</div>
<!-- create white empty box -->
<div id="boxes" class="bodytext">
<!-- things that go in the box -->
<div id="dialog" class="window">
<strong>Disclaimer and Risk Warnings</strong>
<br />
<br />
<div class="bodytext" style="overflow: auto; height: 160px; width: 500px; border: activeborder 1px solid;">
</div>
<br/>
<strong> Please select the user type that applies to you</strong>
<br/>
<input type="radio" name="rdotnc" id="rdo1" />Private Clients
<input type="radio" name="rdotnc" id="rdo2"/>Professional Intermediaries
</asp:RadioButtonList>

<p>
<input id="AcceptButton" type="button" value="I Agree" class="close" style="margin-left: 215px" />
</p>
</div>
</div>

Javascript

$('.window .close').click(function (e) {
//$.cookie("CamSession1", "CAM");
if ($('#rdo1').is(':checked')) {
window.location.replace("http://www.stackoverflow.com");
}
else if ($('#rdo2').is(':checked')) {
window.location.replace("http://www.exchange.com");
}
$('#mask').hide();
$('.window').hide();
});

Check fiddle here

How to check a radio button with jQuery?

For versions of jQuery equal or above (>=) 1.6, use:

$("#radio_1").prop("checked", true);

For versions prior to (<) 1.6, use:

$("#radio_1").attr('checked', 'checked');

Tip: You may also want to call click() or change() on the radio button afterwards. See comments for more info.

How to get value of selected radio button?

var rates = document.getElementById('rates').value;

The rates element is a div, so it won't have a value. This is probably where the undefined is coming from.

The checked property will tell you whether the element is selected:

if (document.getElementById('r1').checked) {
rate_value = document.getElementById('r1').value;
}

Or

$("input[type='radio'][name='rate']:checked").val();


Related Topics



Leave a reply



Submit