mardi 12 février 2019

If input value is "something" add onclick to the button

I want to add onclick event to the button if input value is "Greece" or "UK". If value is something else, onClick must be removed.

<form class="search-options">
    <input id="test" type="text" value="france" />
    <input id="test2" type="text" value="greece" />
    <input id="test3" type="text" value="UK" />
    <input id="test" type="text" value="spain" />
</form>
<button id="search-button">Search</button>
<script>
    $('.search-options').find("input[value='greece']").each(function(){
        document.getElementById("search-button").onclick = "Suggestion.submit();";
    });
</script>

If input value is Greece, button must have onclick="Suggestion.submit();"

Does anyone know what I'm doing wrong?

Aucun commentaire:

Enregistrer un commentaire