0

there was a ton of different ways I seen to do this here on stackoverflow. However, I have tried them and can't get it to work.

Here is my current code.

http://jsfiddle.net/tech0925/C9Z8N/5/

Here is the javascript

function printcardCheck() {
       if (document.getElementById('print_card').checked) {
            document.getElementById('printvoucher-receiver').style.display = 'block';
            document.getElementById('printvoucher-receiver').style.padding = '10px 0 0 0';
            document.getElementById('print_cards').value = 'Add this value';
        } 
                   else document.getElementById('printvoucher-receiver').style.display = 'none';
}

See the fiddle link above.

2
  • What is your expected result? I mean, there is no element with id giftvoucher-receiver, and you haven't even defined mailcardCheck(). Commented Jan 23, 2014 at 17:07
  • Hi, sorry abou that. That was other code that I did not bring over. I updated my code and fiddle. Commented Jan 23, 2014 at 17:14

2 Answers 2

1

http://jsfiddle.net/DerekL/Y4YNs/

I believe you want to do something like this. I will change it to native JS later.

<form>
    <label>
        <input type="radio" name="set1" value="A">A</label>
    <label>
        <input type="radio" name="set1" value="B">B</label>
    <label>
        <input type="radio" name="set1" value="C">C</label>
</form>
<div class="more" id="A">Some more options for A</div>
<div class="more" id="B">Some more options for B</div>
<div class="more" id="C">Some more options for C</div>
$("form input").change(function () {
    $(".more").removeClass("show")
        .filter("#" + $(this).val()).addClass("show");
});
Sign up to request clarification or add additional context in comments.

7 Comments

This would not work for me. I need to use the input tag to carry over the data when the form is submitted. Also, I want to add the value when clicked and remove the value if another option is clicked so the value does not get submitted.
@MagentoMan - You don't have to use value as indicating which options to be shown. You can use whatever attribute you like. Also you can use switch in the change listener to execute specific commands upon different options checked.
Can you take a look at my fiddle and see if you can make it add the value on click and remove it if another option is clicked instead?
@MagentoMan - If you do not want jQuery I can change it to native JavaScript.
I added it to my site but it does not want to work. Can you provide the javascript example? Thanks!
|
1

there should only be one tag that id is 'print_card',and you have two,so when getElementById('print_card') will return the first one, that is the radio

1 Comment

Thank you for pointing that out. I have updated the code and fiddle but it still does not work.

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.