Link to home
Start Free TrialLog in
Avatar of peps03
peps03

asked on

Find specific word(s) in selected option value if matching fill next field value

Hi,

I'm trying to get jQuery to get the value of a selected option in a html form and scan that selected value if it contains one of the predefined (sets of) words.
if it does, that words must be entered as value in the next text field.

Predefined set of words: 'New York', 'LA', 'London'
<select>
<option>School of New York</option>
<option>School of LA</option>
<option>School of Business</option>
<option selected>School of London</option>
</select>

next field: input type="text" >> value='London'

Is this possible??
Thanks!
Avatar of Anuradha Goli
Anuradha Goli
Flag of Ireland image

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>
    <script type="text/javascript">
        function validate() {
            var chkdata = document.getElementById("chkdata").selectedIndex;
            var po = document.getElementsByTagName("option");
            document.getElementById("txtvalue").value = (po[chkdata].value);
        }
            
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <table>
        <tr>
            <td>
                <select id="chkdata">
                    <option value="New York">School of New York</option>
                    <option value="LA">School of LA</option>
                    <option value="Business">School of Business</option>
                    <option selected="selected" value="London">School of London</option>
                </select>
                <input type="text" id="txtvalue" />
                <asp:Button ID="Button1" runat="server" OnClientClick="validate();" Text="Button" />
            </td>
        </tr>
    </table>
    </form>
</body>
</html>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Proculopsis
Proculopsis

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of peps03
peps03

ASKER

@ anuradhay thanks, but i think you use asp, i don't

@Proculopsis, thanks!!! great! it works like a charm!
Its is not asp. You can simple use input type button and on click it validates.