/ Published in: JavaScript

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.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
//Clear the value in the text form when you click other $("#other").click(function(){ $("#inputAmount").attr("value", "").focus().select(); }); $("#donateBox form").submit(function(){ //Check to see if the radio button is checked if($("#other").is(":checked")){ //Take value from the text box var ourValue = $("#inputAmount").attr("value"); //Check to see if we have a value if(ourValue ==="" || ourValue ==="0"){ ourValue = "5"; } //Add it to the radio button $("#other").attr("value", ourValue); } else { return; } });
Comments
