0

I have a php file and I am trying to include another php file in it (for a dropdown) based on what is selected in the radio button but somehow it is not happenning.

To test my work I created a scenario in jsfiddle but there too its not working (i think in jsfiddle i am not loading necessary things which i dont know how to load - please help how to load it in jsfiddle https://jsfiddle.net/7gb4etbw/)

Also need help in javascript function to achieve the above. Appreciate if someone can help me with this. Thank you.

if male is selected, m_ext.php should get included else if female is selected, f_ext.php file should get selected

<?php
if(isset($_POST['submit']))
{
    $gender=$_POST['gender'];
    $_SESSION['gender']=$gender;
    echo "<script language='javascript'>window.location='nextpage.php';</script>";
}
?>
<!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><?php echo $info['title']; ?></title>
    <link href="css/layout.css" rel="stylesheet" type="text/css" />
    <script src="js/jquery-1.11.2.min.js"></script>
    <style type="text/css">
        .red_color {
        color: #F00;
    }
    </style>
<script language='javascript'>
func()
{

    // I am struggling here

}
</script>
</head>
<body>
    <form action="" method="post" name="Form1">
    <table width="100%" border="0" cellpadding="5" cellspacing="5">
        <tr>
            <td >
                <div align="left"><span class="red_color">*</span> 
                    Gender
                </div>
            </td>
            <td>
                <div align="left">
                    <input id="m" onclick="func()" name="mgender" value="Male" type="radio"  />
                    Male
                    <input id="f" onclick="func()" name="fgender" value="Female" type="radio" />
                    Female
                </div>
            </td>
        </tr>
        <tr>
            <td >
                <div align="left"><span class="red_color">*</span>
                    Message
                </div> 
            </td>
            <td >
                <div align="left">
                    <select name="txtname" id="txtid"">
                        <option value="" selected="selected">-Select-</option>
                        <?php include("m_ext.php"); ?>
                    </select>
                </div>
            </td>
        </tr>
    </table>
</body>

</html>
Mumbai CabinCrew
  • 341
  • 2
  • 4
  • 14
  • 2
    Repeat after me - PHP is server-side, JavaScript is client-side. You cannot perform a PHP file include with JavaScript. – Jay Blanchard Jul 12 '16 at 16:43
  • yes i understand that. i dont want to include flies in the function `func()` May be the function can return a value saying which gender a selected and that value can be used to decide which file to include in the ` – Mumbai CabinCrew Jul 12 '16 at 16:47
  • without writing a javascript function, Is it possible to capture radio button selection and include files with if condition? eg. if male radio button is selected then include m_ext.php else f_ext.php. if yes, then how to write the onclick or onblur? – Mumbai CabinCrew Jul 12 '16 at 16:56
  • You cannot do it. You would have to use AJAX to retrieve values from the PHP *or* you would have to do a page reload. – Jay Blanchard Jul 12 '16 at 16:59
  • omg! i dont know ajax at all. i dont want a page reload. i hope i get an answer to this from an ajax expert. btw i edited the subject. by mistake i wrote dropdown instead of radio button. – Mumbai CabinCrew Jul 12 '16 at 17:01
  • I am an AJAX expert. You need to learn AJAX if you want to do this and there are literally thousands of tutorials online. – Jay Blanchard Jul 12 '16 at 17:04
  • I researched a lot, spent a lot of time and struggled a lot to write the code i posted in the question. I never felt that ajax would be a solution. i dont know how much lines of ajax code would do the trick but for putting one condition i really have no patience to ready those thousands of tutorials. Thank you for your time and please remove the duplicate mark as i dont feel it is an exact duplicate of any question. – Mumbai CabinCrew Jul 12 '16 at 17:46
  • No - it is totally a duplicate. You don't have to read thousands of tutorials. One, maybe two good ones. If you're opposed to learning then programming/web development is not what you want to do. – Jay Blanchard Jul 12 '16 at 17:57

0 Answers0