php mandatory field based on drop down list value
<p>I have a form in PHP which has drop downlist and a textboxt which shows and hide bases on dropdown list value. I did the show and hide using javascript.</p>

<p>My question is I want to make the text box mandatory when it become visible and an error to appear if the user left the textbox empty.</p>

<p>I did the form validation using <code>preg_match</code> but how to do the conditional mandatory based on the dropdown list selected value?</p>

<p><strong>EDIT:</strong></p>

<p>here is my show/hide feild in js</p>

<pre><code>&lt;script type="text/javascript"&gt;
function showfield(name){
    if(name != 'High School')
        document.getElementById('div1').style.display="block";
    else
        document.getElementById('div1').style.display="none";
}

function hidefield() {
    document.getElementById('div1').style.display='none';
}
&lt;/script&gt;
</code></pre>

<p>and this is my php validation</p>

<pre><code>if(preg_match("/^[A-Z][a-zA-Z ]+$|\p{Arabic}/u", $_POST["name"]) === 0)
    $errname = '&lt;p class="errText"&gt;Please enter your full name &lt;/p&gt;';' 
</code></pre>
