If radio button checked, then submit to different page

前端 未结 4 388
感情败类
感情败类 2021-01-27 01:06

I have this:

相关标签:
4条回答
  • 2021-01-27 01:45

    You can use form.submit() as onclick-handler (not onchange) and change the action, too.

    <input type="radio" name"rubrik" value="private" onclick="this.parentNode.action='yourOtherFile.php'; this.parentNode.submit()"></input>
    
    0 讨论(0)
  • 2021-01-27 01:47

    you can do this by modifying the Form into:

    <form method="post" id="kl" action="step2.php">
    
    <input type="radio" class="radio" rel="step2.php" name="rubrik" value="bussines"></input>
    <input type="radio" class="radio" rel="step2a.php" name"rubrik" value="private"></input>
    
    <input type="image" value="submit" src="/images/submit.png" alt="Submit" />
    
    </form>
    

    I added rel attribute to radio buttons. each has a value of the url. I also added a class to get the element with jQuery.

    Now, you will need some Javascript, i will use jQuery code:

    $('.radio').click(function (){
       rad = $(this);
       radRel = rad.attr('rel');
       $('form#kl').attr('action', radRel);
    });
    
    0 讨论(0)
  • 2021-01-27 01:52

    There are multiple ways of doing it, depending on what you want exactly.

    Check this one out, it might help you get there; Radio Button to open pages

    0 讨论(0)
  • 2021-01-27 01:54

    You could do this with JavaScript (bind a submit listener that checks the value of the radio button and then sets the action property of the form), but it would be simpler and more reliable to do something (server side) along the lines of:

    <form ... action="step-selector.php">
    

    and

    <?php
        if (isset($_POST['rubrik']) && $_POST['rubrik'] == 'bussines') {
            include('step2.php');
        } elseif (isset($_POST['rubrik']) && $_POST['rubrik'] == 'private') {
             include('step2a.php');
        } else {
             include('error-state.php');
        }
     ?>
    
    0 讨论(0)
提交回复
热议问题