We help IT Professionals succeed at work.

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

peps03 used Ask the Experts™

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'
<option>School of New York</option>
<option>School of LA</option>
<option>School of Business</option>
<option selected>School of London</option>

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

Is this possible??
Watch Question

Do more with

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

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <script type="text/javascript">
        function validate() {
            var chkdata = document.getElementById("chkdata").selectedIndex;
            var po = document.getElementsByTagName("option");
            document.getElementById("txtvalue").value = (po[chkdata].value);
    <form id="form1" runat="server">
                <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>
                <input type="text" id="txtvalue" />
                <asp:Button ID="Button1" runat="server" OnClientClick="validate();" Text="Button" />

Open in new window

Try this jsfiddle.


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

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

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