We help IT Professionals succeed at work.

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

peps03
peps03 used Ask the Experts™
on
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!
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Anuradha GoliSystems Development / Support Specialist

Commented:
<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

Try this jsfiddle.

Author

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

@Proculopsis, thanks!!! great! it works like a charm!
Anuradha GoliSystems Development / Support Specialist

Commented:
Its is not asp. You can simple use input type button and on click it validates.