Hi.
Personally, I would use AJAX to do this, but this can easily be done using PHP.
The complication here is that PHP is server-side, which means that by the time your user even gets the chance to see the <select> drop-down, the PHP script will already have completed it's job.
What you need to do is have PHP submit the <select> box first, and hold of posting the rest of the code until the form has been submitted with a gender value before re-posting the data.
Consider this:
-
<form name="genderForm" action="?" method="post">
-
<?php
-
// Check if all the info has been submitted
-
if(isset($_POST['submitButton']))
-
{
-
// Process the form
-
echo "<h3>Complete!</h3>";
-
}
-
-
// Check if the gender has been selected
-
else if(isset($_POST['gender']) && $_POST['gender'] != "null")
-
{
-
// Print some gender specific content
-
if($_POST['gender'] == "male") {
-
echo 'Enter you wifes name: <input type="text" name="wifeName" /><br />';
-
}
-
else {
-
echo 'Enter you husbands name: <input type="text" name="hubbyName" /><br />';
-
}
-
-
// And of course the submit button
-
echo '<input type="submit" name="submitButton" value="submitted" />';
-
}
-
-
// Nothing has been sent.
-
else
-
{
-
// Show the gender <select> box.
-
echo <<<HTML
-
Gender: <select name="gender" onchange="javascript: this.parentNode.submit();">
-
<option value="null" selected="selected">--Select please--</option>
-
<option value="female">Female</option>
-
<option value="male">Male</option>
-
</select>
-
HTML;
-
}
-
?>
-
</form>
-
This simply prints a gender <select> box. Once you select a gender, it automatically submits the form and loads the gender-specific form elements.
Once the submit button has been pressed, it should process the data.
It probably won't work exactly like you want yours to work, but it should at least point you in the right direction.
Let me know if something is unclear.
P.S.
Please use [code] tags when posting your code examples. (See
How to ask a question)
[code] ... Code goes here... [/code]
Thank you.
Moderator