1

I have a page that I can use merge fields from a CMS to dynamically adjust content; however, this functionality doesn't work with button text. Therefore, I need to use a normal text field and then take the value from that field and push it to the button text.

I thought this would work, but something it's not working right. Can anyone help me figure out what I am doing wrong?

<div id="ctatext" class="ctabutton">Request Pricing</div>
<input type="submit" value="Get Started" data-wait="Please wait..." id="ctabutton" class="_2-0-yellow-btn-2 request w-button">

<script>
    $(document).ready(function () {
    let btntext = $('.ctabutton').text();
    $('input._2-0-yellow-btn-2 request w-button').val(btntext); 
});
</script>
  • Does this answer your question? [Add a string of text into an input field when user clicks a button](https://stackoverflow.com/questions/13941055/add-a-string-of-text-into-an-input-field-when-user-clicks-a-button) – Abdelrahman Hatem Jul 27 '21 at 00:42

1 Answers1

0

I would use the Id's instead of the classes, since they are present.

The current selector you are using is invalid.

It should be

$('input._2-0-yellow-btn-2.request.w-button').val(btntext); 
// vs
$('input._2-0-yellow-btn-2 request w-button').val(btntext); 
<div id="ctatext" class="ctabutton">Request Pricing</div>
<input type="submit" value="Get Started" data-wait="Please wait..." id="ctabutton" class="_2-0-yellow-btn-2 request w-button">

<script>
    $(document).ready(function () {
    let btntext = $('#ctatext').text();
    console.log(btntext);
    $('#ctabutton').val(btntext); 
});
</script>
David Lebee
  • 596
  • 4
  • 14