A
Anonymous
Guest
hello,
I am trying to create a drop down list where users can select their title Mr, Mrs etc and I have the code below:
This is a form that will POST back to itself so at the top of the page I have included the next bit of code to prevent the variable $_POST['title'] from being undeclared on first loading the page:
However, when I load the page, I find the default value of the options set to index 4 of my $titleoption array "Ms" and no matter how much I stare at my code, I can't figure out why it would do this.
Can anyone help?
I am trying to create a drop down list where users can select their title Mr, Mrs etc and I have the code below:
Code:
<select name="title">
<?php
$titlevalue=array(0,'Mr','Mrs','Miss','Ms');
$titleoption=array('Please Select','Mr','Mrs','Miss','Ms');
for($i=0;$i<=4;$i++){
echo "<option value=\"".$titlevalue[$i]."\"";
if($titlevalue[$i]==$_POST['title']){
echo " selected";
}
echo ">".$titleoption[$i]."</option>";
}
?>
</select>
This is a form that will POST back to itself so at the top of the page I have included the next bit of code to prevent the variable $_POST['title'] from being undeclared on first loading the page:
Code:
if(!isset($_POST['submit'])){
$_POST['title']=0;
}
However, when I load the page, I find the default value of the options set to index 4 of my $titleoption array "Ms" and no matter how much I stare at my code, I can't figure out why it would do this.
Can anyone help?