jQuery radio button donate submit


/ Published in: JavaScript
Save to your folder(s)

This snippet is useful on donate forms. If you have a radio button for other value, then this will clear the current value in the text input box, and attach the user in putted value to the other radio button.


Copy this code and paste it in your HTML
  1. //Clear the value in the text form when you click other
  2. $("#other").click(function(){
  3. $("#inputAmount").attr("value", "").focus().select();
  4. });
  5.  
  6. $("#donateBox form").submit(function(){
  7. //Check to see if the radio button is checked
  8. if($("#other").is(":checked")){
  9. //Take value from the text box
  10. var ourValue = $("#inputAmount").attr("value");
  11. //Check to see if we have a value
  12. if(ourValue ==="" || ourValue ==="0"){
  13. ourValue = "5";
  14. }
  15. //Add it to the radio button
  16. $("#other").attr("value", ourValue);
  17. } else {
  18. return;
  19. }
  20. });

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.