SitePoint Sponsor

User Tag List

Results 1 to 14 of 14
  1. #1
    SitePoint Addict
    Join Date
    May 2013
    Posts
    203
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    R-click first div box and INSPECT ELEMENT why not applied .b3choosen class when click

    i used something like
    Code:
    document.getElementById("b1br").onclick = function () {
         document.getElementById("b1br").className += " MyClass2";
    }

    i used this after page loads but does not work? b1br element is above onclick assignment, well?

    go here www.poliscarhire.com try book car when reach http://www.poliscarhire.com/customer...ing-review.php study source, the blue clickable divs are the ones mentioned, well? why no change??? R-click first div box and INSPECT ELEMENT why not applied .b3choosen class when clicked?

  2. #2
    Gre aus'm Pott gold trophysilver trophybronze trophy
    Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    5,997
    Mentioned
    219 Post(s)
    Tagged
    12 Thread(s)
    Hi,

    You can write that:

    Code:
    document.getElementById("b1br").onclick = function () {
         document.getElementById("b1br").className += " MyClass2";
    }
    Like this:

    Code:
    document.getElementById("b1br").onclick = function () {
         this.className += " MyClass2";
    }
    Regarding your question, when I look at the Dev Console in Chrome I see:

    Code:
    Uncaught TypeError: Cannot set property 'onblur' of null validationAJAXreadyBOOKnoAcYesAcNew.js:11
    which is probably stopping any further scripts from executing.
    Either way, you'll want to get this fixed first.

  3. #3
    SitePoint Addict
    Join Date
    May 2013
    Posts
    203
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Either way, you'll want to get this fixed first.

    onblur is applied to an element that appears dynamically with php when click SOCIAL REGISTER where you return after some secs to this page.... what the solution, include onblur js code inside php (html) block?

  4. #4
    Gre aus'm Pott gold trophysilver trophybronze trophy
    Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    5,997
    Mentioned
    219 Post(s)
    Tagged
    12 Thread(s)
    Can you try commenting it out for the time being, to see if that makes a difference to your initial problem.

  5. #5
    SitePoint Addict
    Join Date
    May 2013
    Posts
    203
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    sitepoint-js-css-exp-lesser.jpg

    i get another non in js file but in js embedded in php file...

  6. #6
    Gre aus'm Pott gold trophysilver trophybronze trophy
    Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    5,997
    Mentioned
    219 Post(s)
    Tagged
    12 Thread(s)
    Sorry, I meant comment out line 11 in the file validationAJAXreadyBOOKnoAcYesAcNew.js

    This is:

    Code JavaScript:
    document.getElementById("email").onblur = checkUsername;

  7. #7
    SitePoint Addict
    Join Date
    May 2013
    Posts
    203
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    i did exactly that but got what is screenshoted...

  8. #8
    Gre aus'm Pott gold trophysilver trophybronze trophy
    Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    5,997
    Mentioned
    219 Post(s)
    Tagged
    12 Thread(s)
    Quote Originally Posted by lse123 View Post
    i did exactly that but got what is screenshoted...
    Oh dear.

    You need to comment out two lines in your initPage9 function

    Code JavaScript:
    document.getElementById("email").onblur = checkUsername;
    document.getElementById("usernameLoading").style.display = "none";

    Both of these lines try to reference an element which doesn't exist on load, so they are superfluous anyway.

    If you dynamically add these elements according to how the user interacts with your page, you could always just check first to see if they exist first:

    Code JavaScript:
    var email = document.getElementById("email");
    if(email !=null){
      email.onblur = checkUsername;
    }
     
    var unameLoading = document.getElementById("usernameLoading");
    if (unameLoading !=null){
      unameLoading.style.display = "none";
    }

    Hope that helps.

  9. #9
    SitePoint Addict
    Join Date
    May 2013
    Posts
    203
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    i did replace code but got two new identical exactly error in js :

    "Uncaught TypeError: Cannot read property 'style' of null"

    js embedded this time here >>>

    http://www.poliscarhire.com/customer...ing-review.php

  10. #10
    SitePoint Addict
    Join Date
    May 2013
    Posts
    203
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    As i noticed these error non shown in chrome > when the php generates the code and this when press SOCIAL REGISTER > return to page itself (prior press to register(insert more data prior press required)) > page no errors...well?

  11. #11
    SitePoint Addict
    Join Date
    May 2013
    Posts
    203
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    also note during php code inject on page:

    i eject also the below code

    in dw line of php 18090line
    Code:
    	<script type="text/javascript">
    			document.getElementById("b3br").className += " b3choosen";
    			
    			document.getElementById("b1br").className = "";
    			document.getElementById("b1br").className += "b3";
    			
    			document.getElementById("b2br").className = "";
    			document.getElementById("b2br").className += "b3";		
    	</script>

  12. #12
    Gre aus'm Pott gold trophysilver trophybronze trophy
    Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    5,997
    Mentioned
    219 Post(s)
    Tagged
    12 Thread(s)
    Hi there,

    Quote Originally Posted by lse123 View Post
    i did replace code but got two new identical exactly error in js :

    "Uncaught TypeError: Cannot read property 'style' of null"

    js embedded this time here >>>

    http://www.poliscarhire.com/customer...ing-review.php
    I looked at the page you link to, but cannot see any JS errors.
    I do see two 404 errors for a png anda gif file, but these won't be affecting much.

    Quote Originally Posted by lse123 View Post
    As i noticed these error non shown in chrome > when the php generates the code and this when press SOCIAL REGISTER > return to page itself (prior press to register(insert more data prior press required)) > page no errors...well?
    I'm not too sure what you mean here, but the lack of errors are probably down to the fact that clicking on "SOCIAL REGISTER" inserts the missing elements (email and usernameLoading) into the page.

    Quote Originally Posted by lse123 View Post
    also note during php code inject on page:

    i eject also the below code

    in dw line of php 18090line
    Code:
    	<script type="text/javascript">
    			document.getElementById("b3br").className += " b3choosen";
    			
    			document.getElementById("b1br").className = "";
    			document.getElementById("b1br").className += "b3";
    			
    			document.getElementById("b2br").className = "";
    			document.getElementById("b2br").className += "b3";		
    	</script>
    I'm not sure what you mean by eject and why you would want to remove this code.

    The best advice I can give you now is to try and make a page where we can reproduce the error without having to click on this, do that, go back to the previous page etc.
    I appreciate the fact that this must be frustrating, but it is the only way we are going to be able to bring this forward.

  13. #13
    SitePoint Addict
    Join Date
    May 2013
    Posts
    203
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    "I looked at the page you link to, but cannot see any JS errors." press 1st or second blue div button to see embedded js errors...
    when press 3rd blue div
    " the missing elements (email and usernameLoading) into the page." but fixed problem with
    with social register press=eject php no error,...
    var email = document.getElementById("email");
    if(email !=null){
    email.onblur = checkUsername;
    }

    var unameLoading = document.getElementById("usernameLoading");
    if (unameLoading !=null){
    unameLoading.style.display = "none";
    }

  14. #14
    Gre aus'm Pott gold trophysilver trophybronze trophy
    Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    5,997
    Mentioned
    219 Post(s)
    Tagged
    12 Thread(s)
    Hi there,

    I'm sorry, but I don't really know what else I can tell you here.
    The error is caused by the fact that you are trying to set the style property of an element that doesn't exist in the DOM.

    You can get around it like this:

    Code JavaScript:
    var elementToTestFor = document.getElementById("elementID");

    elementToTestFor should now either be the element or null, so:

    Code JavaScript:
    if (elementToTestFor != null){
      // Code here when the Element Exists.
    }


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •