2

Hey all i am wondering why i am getting this error with the following code:

The javascript:

 <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js"></script>
 <script src="http://max.jotfor.ms/min/g=jotform?3.0.3359" type="text/javascript"></script>

 function checkInput() {
if ($("#input_3") === null) {
    $('#error1').css('display', 'block');
        $('#error1').css('visibility', 'visible');
}
 ....

The CSS:

 .ErrorBlock1 {
    display: none;
    visibility: hidden;     
    background-color:#F00;
    color:#FFF;
    font-family:Arial, Helvetica, sans-serif;
    font-size:10px;
 }

the HTML:

 <div id="cid_3" class="form-input-wide">
    <input name="q3_firstName3" type="text" class="form-textbox validate[required, Alphabetic]" id="input_3" size="25" style="width: 265px; height: 25px; background: transparent url(textfield.png) no-repeat center center; border: none;" onBlur="checkInput();" />
 <div class="ErrorBlock1" id="error1">First Name Req.</div>
 </div>

I am getting this error when running it:

Timestamp: 9/17/2012 9:10:15 AM
Error: TypeError: $("#error1") is null

Why am i getting this???

3
  • display: visible is invalid CSS. Commented Sep 17, 2012 at 13:10
  • 1
    This means jQuery is not loaded. Commented Sep 17, 2012 at 13:10
  • Corrected. Thanks. But still have the error. Commented Sep 17, 2012 at 13:10

2 Answers 2

4

$('#input_3') will never return null. It will always be a jQuery object.

Check for its existence with $('#input_3').length != 0.

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

1 Comment

Seems to be related to something with the JotForm JS... geerrr. When i take that js out it works.
2

For you use both display and visibility :

jsBin demo

CSS:

.ErrorBlock1 {
    display: none; 
    visibility: hidden;
    background-color:#F00;
    color:#FFF;
    font-family:Arial, Helvetica, sans-serif;
    font-size:10px;
 }

jQUery:

function checkInput() {
  if ($("#input_3").val().length) {
      $('#error1').show().css({visibility:'visible'});
  }else{
      $('#error1').hide().css({visibility:'hidden'});
  }
}

4 Comments

I'm getting Error: TypeError: $("#input_3") is null with that.
if ($("#input_3").val().length > 0) { } is probably what he meant.
Seems to be related to something with the JotForm JS... geerrr. When i take that js out it works.
@roXon: Thanks for the demo there! It helped a lot!

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.