Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8587905
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T22:41:06+00:00 2026-06-11T22:41:06+00:00

I need a JavaScript that can insert an attribute to a field and also

  • 0

I need a JavaScript that can insert an attribute to a field and also remove it when the user deselects the field.

Here is the code I’m using for the radio select:

<script>
$(document).ready(function() {
    $("input[name$='sel']").click(function() {
        var test = $(this).val();

        $("div.desc").hide();
        $("#sel" + test).show();
    });

    if (test == "CreditCard") {
        $("#card").addClass("validate[custom[card]] text-input");
    } else {
        $("#card).removeClass("validate[custom[card]] text-input");
    }
});
</script>

Field code:

<table><tr><td>

<p>
Credit/Debit Card<lable  style="margin-right:1px;"></lable><input type="radio" name="sel" id="sel"  value="CreditCard" />
</p> 
<p>
Paypal<input type="radio" id="sel"  name="sel" value="Paypal"   />
</p>
<p>
Wire Transfer<input type="radio" id="sel"  name="sel" value="WireTransfer"  />
</p>
<!====================================================================================>
</td><td>
<!====================================================================================>
<div id="selCreditCard" class="desc">

<label for="card"><strong>Card Number<font color=red size=3> *</font></strong></label>
        <input name="card"   type="text"  id="card" value=""  style="width:85px;" />  
</div>
<!====================================================================================>
<div id="selPaypal" class="desc" style="display: none;margin-left:20px;margin-top:1px;margin-bottom:1px;">
    paypal
</div>
<!====================================================================================>
<div id="selWireTransfer" class="desc" style="display: none;margin-left:20px;margin-top:0px;margin-bottom:-5px;">

Transfer

</div>
<!====================================================================================>
</td></tr></table>
​

This is the attribute that needs to be inserted to the “card” input field:

class="validate[custom[card]] text-input"

When the user selects the radio with the value CreditCard, the attribute will be inserted to the input field, and when the user deselects the radio with the value CreditCard the attribute will be removed.

Link for fiddle:
FIDDLE

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T22:41:07+00:00Added an answer on June 11, 2026 at 10:41 pm

    telexper, there are lots of wrong things in your code, and unfortunatelly i dont have the time to explain right now.

    but i will leave a working code for you here: http://jsfiddle.net/RASG/DSrLS/

    just click “Credit/Debit Card” and the class nowitsadded wil be added to the input field, which will turn red.

    HTML

    <input type="radio" id="sel1" name="sel"> Credit/Debit Card
    
    <br>
    
    <input type="radio" id="sel2" name="sel"> Paypal
    
    <br>
    
    <input type="radio" id="sel3" name="sel"> Wire Transfer
    
    <br>
    <br>
    
    <div id="selCreditCard" class="desc">
        Card Number <input name="card" type="text" id="card" value="">
    </div>
    

    JS

    $('#sel1').click(function() { $('#card').addClass('nowitsadded') })
    

    CSS

    .nowitsadded {background-color: red}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I have these lines of javascript code that I need to remove all
I need to insert an iframe into a div using javascript. I need this
I need to produce a small script that users can insert in to their
i need a javascript function that able to check for digit and - only.
I need 2 simple JavaScript functions that read and change the color of a
I need a random object generator in JavaScript that generates a variety of objects
I have an array in javascript that I need to join and send through
I need to create a javascript function that checks if it has been a
I need to get textbox that exits in Formview inserttemplate via javascript. Both return
Just need a little bit of Javascript to warn people that press the back

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.