Jump to content

javascript dropdown box selcted value validation


NaniG

Recommended Posts

Hi all,

 

    Here is the my code.

 

     

<form name='formx'>
        <select id="sel" onchange="ShowHide(this,'other');">
            <option value="">- select -</option>
            <option value="option1">Option 1</option>
            <option value="option2">Option 2</option>
            <option value="option3">Option 3</option>
            <option value="option4">Option 4</option>
            <option value="other">Other</option>
        </select>
       <label id="other" style="display:none;">
   		<input type="text" name="example" />
   </label> 
    </form>

<script type="text/javascript" language="javascript">
function ShowHide(obj, id1)
{
txt1 = obj.options[obj.selectedIndex].value;
document.getElementById(id1).style.display = 'none';

if ( txt1.match(id1) ) 
{
	document.getElementById(id1).style.display = 'block';
}	
}
</script>

 

when i selected "other", it will displaying the text box. Now, how can i validate these textbox ? It should be non-empty field.

 

Thanks in Adv.

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.