How do I write the IF Statement for a dropdown listbox in PHP

I have the following form elements:

//Last Name
 <label for="lastName">Last Name<span class="required">*</span></label>
                    <input name="lastName" id="lastName" type="text" value="" />

//Sex
 <label>Sex<span class="required">*</span></label>
                    <div class="radioList">
                        <div class="radioPair">
                            <label>
                                <input name="sex" type="radio" value="Male"  />&nbsp;Male
                            </label>
                        </div>
                        <div class="radioPair">
                            <label>
                                <input name="sex" type="radio" value="Female"  />&nbsp;Female
                            </label>
                         </div>

//Session Number

                      <label>Please select the session number: </label>
                      <select name="threeWeekSessionNum" id="threeWeekSessionNum"> <option value = "">Session Number</option>
                       <option value = "1">1</option>
                       <option value = "2">2</option>  
                       <option value = "3">3</option>
                       <option value = "4">4</option>
                       <option value = "5">5</option>  
                       <option value = "6">6</option>
                       <option value = "7">7</option>
                        </select>  

The validation for the last name and radio button is as follows:

if( !$("input[name='lastName']").val() ){
                alert('Please enter a Last Name');
                return false;    

if( !$("input:radio[name='sex']:checked").val() ){
                alert('Please enter a Sex');
                return false;    
            }

I would like some help in writing the code for the listbox validation as I am not familiar with the syntax. If the user selects "Session" (meaning they didn't make an actual selection), then I would like it to throw up an alert like the others.
geeta_m9Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

F PCommented:
if($("#threeWeekSessionNum option:selected").text() == "Session Number")
{
    alert("You shall not pass... without selecting a valid session number");
    event.preventDefault();
    return false;
}
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
F PCommented:
Of course, I would wrap all your validation on an anonymous function triggered when the form is submitted, or button clicked.
0
F PCommented:
BTW, that code I submitted was javascript. If you want to do validation in PHP, I would use this:

// I used REQUEST because I don't know if you're POSTing or GETting data
// --- use $_POST or $_GET depending on which you use because it's faster than parsing those + $_COOKIE

if(strpos(strtolower($_REQUEST['threeWeekSessionNum']), 'session') !== FALSE)
{
    echo 'Didn't select a session number!";
}
0
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

Vimal DMSenior Software EngineerCommented:
Hi,

$op2 .= "\n\t<option <?PHP if($d['area_id']=='')echo 'disabled=disabled'; ?> value=\"{$d['area_id']}\">{$d['area']}</option>";


<select id="area" name="area">
<?php echo $op2;?>
</select>
0
Scott MadeiraCommented:
Another thing you can do on the PHP side is set the option value for Session to "#"  (you have it set to "") and test for an integer response  in your validation.

if( ! is_int( $_REQUEST['threeWeekSessionNum']))
{
    echo 'Didn't select a session number!";
}

Open in new window


Also, I'm not a javascript guru but you should be able to do a similar check for an integer selection there as well...
0
geeta_m9Author Commented:
Your solution works great, Frank! Thank you to all of you for your help.
0
F PCommented:
Glad I could help!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.