Skip to content

Instantly share code, notes, and snippets.

@marcus-at-localhost
Created June 20, 2022 14:31
Show Gist options
  • Save marcus-at-localhost/c54760a91320bb6ca37eaf84485c9aaa to your computer and use it in GitHub Desktop.
Save marcus-at-localhost/c54760a91320bb6ca37eaf84485c9aaa to your computer and use it in GitHub Desktop.
[Change Button Text Depending on Another Field] #js
<form>
<input class="kb-field-2">
<button class="kb-forms-submit">A</button>
</form>
<script>
const field = document.getElementsByClassName('kb-field-2')[0];
field.addEventListener("keyup", () => {
let btn = document.getElementsByClassName('kb-forms-submit')[0];
if( field.value === "" ) {
btn.textContent = "A";
}else{
btn.textContent = "B";
}
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment