www.webdeveloper.com
Results 1 to 6 of 6

Thread: Problem for dummies

  1. #1
    Join Date
    Jun 2013
    Posts
    20

    Problem for dummies

    as i said in a previous post i'm pretty new with programming in general.

    i only want to know where is the mistake in this simple lines wich seems to do nothing in my javascript.js:


    Code:
    $("#label_informations").click(function(){
    		window.location = 'informations.php';
    		});

    all the scripts are regulary included in my index.htm (other parts of my page work correctly), in index.html i have a label element with this id and i obviously have a informations.php file in the same directory!
    where can be the mistake???

    THX

  2. #2
    Join Date
    Nov 2010
    Posts
    1,090
    I think you would be better with
    Code:
    window.location.href = 'informations.php';
    or
    Code:
    window.navigate('informations.php');
    or
    Code:
    self.location='informations.php';
    or maybe even
    Code:
    top.location='informations.php';
    or (depending on what you want to do)
    Code:
    location.replace('informations.php');

  3. #3
    Join Date
    Jun 2013
    Posts
    20
    i'm sorry but it won't work in any of this cases!
    maybe it's something wrong with the event handler? -.-

  4. #4
    Join Date
    Nov 2010
    Posts
    1,090
    the problem could be that you are attaching the listener (for example in the head) before the element exists (being that you create it in the body). Hard to tell without seeing more code. Generally jQuery is wrapped in a document ready function to avoid that sort of problem. An easy test would be to add an alert to the listener:
    Code:
    $("#label_informations").click(function(){
    alert("clicked!");
    		window.location = 'informations.php';
    		});
    if you don't see the alert, that's most likely the problem. If you do it's something else...

  5. #5
    Join Date
    Jun 2013
    Posts
    20
    i don't see the alert message.
    you got it!!!
    thank you very much!
    so what am i suppused to do to make it work? ))))

  6. #6
    Join Date
    Nov 2010
    Posts
    1,090
    like I say - either wrap it (and the rest of your jQuery) in a document ready function:

    Code:
    $( document ).ready(function() {
    
    $("#label_informations").click(function(){
    alert("clicked!");
    window.location.href = 'informations.php';
    });
    
    // more jQuery stuff
    
    });
    or, in the code, make sure that your script runs after the element has been created in the html:

    Code:
    <body>
    <input id="label_informations" type="button" value="click me!">
    
    <script>
    $("#label_informations").click(function(){
    alert("clicked!");
    window.location.href = 'informations.php';
    });
    
    // more jQuery stuff
    </script>
    </body>
    either will work, it just depends on how your page is set up at the moment.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles