2

I'm using Bootstrap to develop my php platform.

When i try to use this javascript snippet

if(result == "OK"){
    // If the result is OK applies some effects
    $("#signup" + item).removeClass("error");
    $("#signup" + item).addClass("success");
} else {
    // Applies some effects and shows the error
    $("#signup" + item).removeClass("success");
    $("#signup" + item).addClass("error");
}

with this html code

<input class="xlarge" id="signupUsername" name="signupUsername" size="30" type="text">

Nothing happens. The "error" or "success" effects are not applied.

2
  • Are you sure the code is executed? Did you include the right CSS? Did you define the "error" and "success" CSS classes? Does "item" contain the right value? ... Commented Dec 22, 2011 at 11:09
  • The css is correctly included because the page is correctly styled. Error and success classes are defined in the Bootstrap .less files that are correctly compiled by less. Commented Dec 22, 2011 at 11:11

1 Answer 1

4

error and success classes shouldn't be applied to <input>, but to containing <div> with class clearfix:

<div class="clearfix error">
    <input id="errorInput" class="xlarge" type="text" size="30" name="errorInput"/>
</div>

<div class="clearfix success">
    <input id="successInput" class="xlarge" type="text" size="30" name="successInput"/>
</div>

Try changing your code to add/remove classes to parent div.clearfix and see if it works then.

HTML:

<div class="clearfix">
    <input class="xlarge" id="signupUsername" name="signupUsername" size="30" type="text">
</div>

JS:

var div = $("#signup" + item).parent("div.clearfix");
if(result == "OK"){
    div.removeClass("error");
    div.addClass("success");
} else {
    div.removeClass("success");
    div.addClass("error");
}
Sign up to request clarification or add additional context in comments.

Comments

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.