1

I have this code but it just wont work. what could the problem be? Is my syntax wrong or is the whole method wrong?

<input checked="checked" class="form-field" id="IsCurrentlySmokingrightNej" name="IsCurrentlySmokingright" type="radio" value="Nej">
<input class="form-field" id="IsCurrentlySmokingrightJa" name="IsCurrentlySmokingright" type="radio" value="Ja">
    <input id="IsCurrentlySmokingrighttextbox" name="IsCurrentlySmokingright" type="text" style="background-color: rgb(0, 255, 0); float: right; width: 50px;">

javascript:

 $(document).on("change", "IsCurrentlySmokingrightNej", function() {
    var elem = document.getElementById("IsCurrentlySmokingrightNej");
    var ele = $("#IsCurrentlySmokingrighttextbox");
    if (elem.checked) {
        ele.css("background-color", "rgba(0, 255, 0, 1)");
        ele.css("float", "right");
        ele.css("width", "50px");

    }
});

   $(document).on("change", "IsCurrentlySmokingrightJa", function() {
        var elem = document.getElementById("IsCurrentlySmokingrightJa");
        var ele = $("#IsCurrentlySmokingrighttextbox");
        if(elem.checked){
            ele.css("background-color", "rgba(255, 0, 0, 1");//röd
            ele.css("float", "right");
            ele.css("width", "50px");
        }

});
1
  • Add a # before IsCurrentlySmokingrightJa, so $(document).on("change", "#IsCurrentlySmokingrightJa"... Commented Jul 31, 2013 at 12:40

2 Answers 2

3

you missed # in front of id selector

 $(document).on("change", "#IsCurrentlySmokingrightNej", function() {
                      //---^---here

same goes for the rest..

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

Comments

1

You need to give the # or . if it is id then # and if class name then .

$(document).on("change", "#IsCurrentlySmokingrightNej", function() {
                          ^^^ # here as it is id

And one more thing:

var elem = document.getElementById("IsCurrentlySmokingrightNej");

Why are you using this line even though you are not using it anywhere.

2 Comments

I acctually used that code before but i have modified the code a couple of times so now it was only in the way of the code. Thanks!
@DanielGustafsson ok, just to know to understand the question properly. well no prob.

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.