开发者

Using html radio buttons (or alternative) to call a php function without javascript

Is it possible to call a php function when an html radio button is selected?

I'm working on building a donate page for a small non-profit school that will have three options: Donate, Pay Tuition, or Make a Monthly Donation.

I would like for the choice of the radio button to load the rest of the webpage based on their selection. If possible, I'd like to do this without using javascript (if user disabled) or iframes.

Currently, if I'm using javascript, it works with this code:

<html>
<head>
<script type="text/javascript">
function go (url) {
parent.frame_name.location = url;
}
</script>
</head>
<body>
I would like to:
<br />
<input type="radio" name="type" value="donate" onclick="go ('makedonate.php')">Make a Donation
<input type="radio" name="type" value="tuition" onclick="go ('paytuition.php')">Pay My Child's Tuition
<input type="radio" name="type" value="monthly" onclick="go ('makemonthly.php')"开发者_如何学编程>Become a Monthly Sponsor
<iframe name="frame_name" frameborder="0" width="600" height="300"></iframe>
</body>
</html>

Is it possible? Any thoughts?


Put it in a HTML <form> element and add a <input type="submit"> button. Let the form's action point to a single PHP page. In the PHP function behind the PHP page, determine the radio button pressed based on the parameter name and/or value and finally display the rest of page conditionally based on the selected radio button using if-else or switch statement.


Hope this help

Just change the stuff in caps

<?php

 if(isset($_POST['donation']))
  {
   echo "ENTER THE CODE TO BE DISPLAYED IF THEY CLICK DONATION";
  }
 elseif(isset($_POST['pay']))
  {
   echo "ENTER THE CODE TO BE DISPLAYED IF THEY CLICK PAY";
  }
 elseif(isset($_POST['sponsor']))
  {
   echo "ENTER THE CODE TO BE DISPLAYED IF THEY CLICK SPONSOR";
  }
 else
  {

?>

            I would like to:
            <br />

            <form method="POST" action="ENTER PAGE NAME">
            <input type="radio" name="donation" value="donate" >Make a Donation
            <input type="radio" name="pay" value="tuition" >Pay My Child's Tuition
            <input type="radio" name="sponsor" value="monthly">Become a Monthly Sponsor
            <input type="submit" value="Get Info"/>
            </form>

<?php

  }

?>


In short, No.

You can't assign an action to a radio button change event without JavaScript.

If you add a "Change Type" button after the radio buttons I think you can make it work without any JavaScript, but you will need to use an iframe.

See: How do I submit an html form inside an iframe without changing the outer page?


First way: use flash.
Second way: use wizard style pages and store variables in session.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜