Change button link according to radio

Asked

Viewed 183 times

0

Guys it’s a stupid thing I know, but I’m racking my brain, I need help who can thank you. . I am making a simple form, I need to have a rating question, if the person choose the option a link changes example pro google.com, if the person chooses option b the link changes example for yahoo.com.br and if the person chooses option c the link changes example for terra.com.br . I got to it, but it doesn’t work:

  jQuery(function($){
        $('#male, #female, #other').change(function(){
		var volume = $('#male').val();
    var volume = $('#female').val();
    var volume = $('#other').val();
		           
		if (other == "other") {
	            $('.LinkBotao').attr('href', 'http://www.google.com');
		}
		else if (male == "male") {
		    $('.Linkbotao').attr('href', 'http://www.uol.com.br');
		}
		else if (female == "female") {
		    $('.Linkbotao').attr('href', 'http://www.yahoo.com.br');
		}
	});
});
// JavaScript Document
<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
<form action="">
     
     <br>
  <input type="radio" name="gender" value="male"> Male<br>
  <input type="radio" name="gender" value="female"> Female<br>
  <input type="radio" name="gender" value="other"> Other<br>  
     
     <br>
     <a href="#" class="LinkBotao" target="_blank">
       <input type="button" name="aderir" id="aderir" value="aderir"> 
     </a>
</form>

2 answers

0

You need to handle change by name

 $('input[type=radio][name=gender]').change(function() {
        if (this.value == 'male') {
            $('.LinkBotao').attr('href', 'http://www.google.com');
        }else if (this.value == 'female') {
            $('.LinkBotao').attr('href', 'http://www.uol.com.br');
        }else if (this.value == 'other') {
            $('.LinkBotao').attr('href', 'http://www.yahoo.com.br');
        }
 });

0


I made a few minor changes but tried to make as much as possible like your code.

<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
<form action="">

     <br>
  <input type="radio" name="gender" value="male" class="gender"> Male<br>
  <input type="radio" name="gender" value="female" class="gender"> Female<br>
  <input type="radio" name="gender" value="other" class="gender"> Other<br>  

     <br>
     <a href="#" class="LinkBotao" id="button">
       <input type="button" name="aderir" id="aderir" value="aderir"> 
     </a>
</form>
<script type="text/javascript">
     jQuery(function($){
        $('.gender').click(function(){
        var volume = $(this).val();

        if (volume == "other") {
                $('#button').attr('href', 'http://www.google.com');
        }
        else if (volume == "male") {
            $('#button').attr('href', 'http://www.uol.com.br');
        }
        else if (volume == "female") {
            $('#button').attr('href', 'http://www.yahoo.com.br');
        }
    });
});
</script>
  • puts bro didn’t work out for what I need to add

  • what exactly you would need?

  • I asked another question to try to explain, I need in fact is a form of name, email and these radio, that to each radio he sent for a programming in php, to fire an email and return to another page...I thought that only with this doubt could solve, but I couldn’t get rsrsrsrs

  • https://answall.com/questions/368192/alterar-o-link-de-um-bot%C3%A3o-radio-in-a-formulary

Browser other questions tagged

You are not signed in. Login or sign up in order to post.