php - Call Different URL Form JavaScript on Different Radio button selected -
is there way can send data different php urls java script based on radio button selected.
example:
html
html radio button selected call html.php javascript
and
css
css radiobutton selected
then call css.php
html.
<div>choose option:</div> <input type="radio" name="user_options" value="css" /> css <input type="radio" name="user_options" value="jquery" /> jquery <input type="radio" name="user_options" value="html" /> html <input type="radio" name="user_options" value="php" /> php
script php
<script type="text/javascript"> $(document).ready(function () { $("#submit").click(function () { var datahtml = $('input[type="radio"]:checked').val(); if ($('input[type="radio"]:checked').length == "0") { alert("select value"); } else { $.ajax({ type: "post", url: "html.php", data: "htmldata=" + htmldata, success: function () { $("#msg").addclass('bg'); } }); } return false; }); }); </script>
well, that's idea i'm not saying perfect.
what can is, each, button, storing url should reach clicking on it, e.g :
<input type="radio" name="user_options" data-url="http://example.org/css" value="css" /> css <input type="radio" name="user_options" data-url="http://example.org/jquery" value="jquery" /> jquery <input type="radio" name="user_options" data-url="http://example.org/html" value="html" /> html <input type="radio" name="user_options" data-url="http://example.org/php" value="php" /> php
as can see, added custom properties each button store destination. then, click event handler, right after datahtml
, can :
var remoteurl=$('input[type="radio"]:checked').data("url");
and replacing
url: "html.php",
by
url: remoteurl,
you'll need adapt names here idea.
hope you
Comments
Post a Comment