Selenium select dropdown option
===

I'm going to say the dreaded words - i'm fairly new to java

But I can't find my answer online in the most obvious places so I'm going to ask the question here

The program i'm testing is a customer database, when you select the Country drop down box, other fields may become mandatory
Amongst those fields is "State"
This field can either be a free text or a drop down box

So i've created an if statement that lets me input free text if the conditions for a state drop down box is not met:


    if (selenium.isElementPresent("xpath=//*[@id='state']/option[2]"))
	{selenium.select("xpath=//select[@id='state']/option","index=2" );}
	
	else	{checkfield("xpath=//td[contains(.,'State/Province:')]/
    preceding-sibling::td[contains(.,'*')]", 
			"xpath=//*[@id='address.state']",
			state1);}

    <td>
    <!-- begin state drop down menu -->
    <select id="state" name="address.state">
    <option selected="selected" value="">Please Select</option>
    <option value="AL">Alabama</option>
    <option value="AK">Alaska</option>
    <option value="WY">Wyoming</option>
    </select>
    <!-- end state drop down menu -->
    </td>


My question may be a very basic one and you guys can probably already see where my code fails

I want to choose option 2 of the drop down box if a drop down box is present, otherwise enter a string which has been declared in the free text box

up until now i've only ever used selenium.select for selecting a label which has specific text 
