SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Guru afridy's Avatar
    Join Date
    Mar 2007
    Posts
    966
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Strange jquery vs js isssue

    Hai folks,


    sorry folks, question delted. little messed up

  2. #2
    Under Construction silver trophybronze trophy AussieJohn's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    776
    Mentioned
    11 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by afridy View Post
    why this code fires before the jquery function finishes?
    Code:
    var nation=document.getElementById("txtnation").value;
    how do i force it to wait till jquery function finsihes

    Well, what happens is that jQuery binds the click event handler and then your script continues executing. The bit inside of the event handler will only be executed when somebody clicks on one of the given elements. If you want to set the "nation" variable based on what someone selects, the solution is simple, just move the assignment into the event handler.

    e.g. something along these lines

    Code JavaScript:
    var nation;
    $("input[name=nation]").click(function(){
      nation = ""// your code...
      //maybe call some function that does something with nation
    });
    var details = {
    . . web: "afterlight.com.au",
    . . photos: "jvdl.id.au",
    . . psa: "usethelatestversion.com"
    }

  3. #3
    SitePoint Guru afridy's Avatar
    Join Date
    Mar 2007
    Posts
    966
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by AussieJohn View Post
    Well, what happens is that jQuery binds the click event handler and then your script continues executing. The bit inside of the event handler will only be executed when somebody clicks on one of the given elements. If you want to set the "nation" variable based on what someone selects, the solution is simple, just move the assignment into the event handler.

    e.g. something along these lines

    Code JavaScript:
    var nation;
    $("input[name=nation]").click(function(){
      nation = ""// your code...
      //maybe call some function that does something with nation
    });
    Thanks buddy!!!!
    yes, undestood.


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
  •