scripting help

Status
Not open for further replies.

squiggleybob

New Member
Messages
11
Reaction score
0
Points
0
hi people, just wondered if anyone could help me with a radio form problem. i have set up a radio form with six outcomes, and a submit button. how can i make it so depending on which is selected you are sent to a different page when submitting?

thanks in advance, rus.
 

garrettroyce

Community Support
Community Support
Messages
5,609
Reaction score
250
Points
63
Use a <button> with an onclick event set to submitform(). Then you'll need to have a javascript function called submitform() that will check which radio is set, change the form action, and then call form.submit().

I'm busy right now, but I'll check back later and try to give you the actual code.
Edit:
OK, here you go:
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Untitled Page</title>
    <script type="text/javascript">
        function formsubmit() {
            var radios = document.getElementsByName("radio1");
            var form = document.getElementsByName("form1")[0];
            if (radios[0].checked) {
                form.action = "page1.htm"; }
            else if (radios[1].checked) {
                form.action = "page2.htm"; }
            else if (radios[2].checked) {
                form.action = "page3.htm"; }
            else if (radios[3].checked) {
                form.action = "page4.htm"; }
            form.submit();
            }
    </script>
</head>
<body>
<form name="form1" action="" method="get" >
    <input type="radio" name="radio1" value="1" checked="checked" />
    <input type="radio" name="radio1" value="2" />
    <input type="radio" name="radio1" value="3" />
    <input type="radio" name="radio1" value="4" />
</form>

<button onclick="formsubmit()" />

</body>
</html>
 
Last edited:

gomarc

Member
Messages
516
Reaction score
18
Points
18
If you want to do it using some php, you can try this:

HTML:
<form name="input" action="gopage.php" method="post">

<input type="radio" 
       checked="checked"
       name="webpage" 
       value="http://www.w3schools.com/" /> w3schools
<br />
<input type="radio" 
       name="webpage" 
       value="http://www.google.com" /> Google
<br />
<input type="radio" 
       name="webpage" 
       value="http://www.yahoo.com" /> Yahoo!
<br />
<input type="submit" 
       value="Submit" />

</form>
... and your gopage.php
PHP:
<?php
IF (ISSET($_POST['webpage']))
{
header("Location: " . $_POST['webpage']);
}

// send error message
echo "Something went wrong!";

?>
 
Status
Not open for further replies.
Top