0

Im trying to prompt for a value that will replace the value for "data-amount", How would you go about doing this?

<html>

<body>

<a href="http://google.com/" class="dwolla_button" data-name="Lease" data-desc="Payments" data-amount="4" data-shipping="0" data-tax="0" data-guest-checkout="true" data-key="xxxxx">Bank </a>


<script type="text/javascript" src="https://www.dwolla.com/scripts/button.min.js"> </script>

</body>

</html>

I have tried to replace using javascript in this manner

<script>
document.getElementByClass("dwolla_button").data-amount="43";
</script>

and have thought about using jquery like this but wasn't sure how to load jquery in the first place

$("a").attr("data_amount", "43")

Any ideas?

the whole code that ive tried fully is

<html>
  <body>

    <a href="http://249lease.webs.com/" class="dwolla_button" data-name="Lease" data-desc="Payments" data-amount="5" data-shipping="0" data-tax="0" data-guest-checkout="true" data-key="sHqCOc31Vh3JiAsPhBfEk5f4D9bAWKLzwaT06ah3Aw65i0gkZl">Bank Account (25¢)</a>


<script type="text/javascript">

document.getElementByClass("dwolla_button")[0].setAttribute("data-amount", "43");
</script>  

    <script type="text/javascript" src="https://www.dwolla.com/scripts/button.min.js"> </script>

  </body>
</html>
0

3 Answers 3

1

The simple JS solution is:

document.getElementsByClassName("dwolla_button")[0].setAttribute("data-amount", "43");

Which would work if the dwolla_button is the first (or only) dwolla_button in the page.

Sign up to request clarification or add additional context in comments.

5 Comments

Yay for vanilla JS (just saw the OP may not have jQuery already loaded)
how would i write this into my script i tried adding this <script type="text/javascript"> document.getElementByClass("dwolla_button")[0].setAttribute("data-amount", "43"); </script>
That should work. But you have to make sure that there's only one <a> with the class dwolla_button in the page, or that the one you are targeting is the first dwolla_button in the page. Do you have a specific page you can link to, or can you give me the entire HTML file?
Is it still not working? Try to put your custom script after the dwolla script. In other words, put it right before the </body> tag, to make sure the other script does not override yours.
Right. Sorry for the typo.
0

if you already have jQuery, jQuery.data() is what you're looking for:

$(".dwolla_button").data("amount", 43)

it will use HTML 5's data properties where supported, and its own implementation in older browsers.

Comments

0

include this script that google provides for loading jquery :-

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.