SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Addict
    Join Date
    Sep 2003
    Location
    CA
    Posts
    264
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Passing JS variable to form?

    I'm using the Maxmind Geoip database to pull information about the visitor:

    MaxMind - GeoIP JavaScript Web Service

    (namely the city and state).

    I want to use that information to prepopulate one of the fields on my form (say city)
    Code:
    <input id="awf_field-24855776city" type="text" class="text" name="custom US Address (City)" tabindex="502" />
    Anyone have any idea how I can do this? I tried the document.write function and it doesn't output to my value="" field with the correct data. Thanks!

  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)
    After everything has loaded, (i.e. window.onload), you can assign something to the value of a text field like so:

    Code JavaScript:
    document.getElementById("someTextField").value = "some value";
     
    // in your app, this should do the trick:
    document.getElementById("awf_field-24855776city").value = geoip_city();
    var details = {
    . . web: "afterlight.com.au",
    . . photos: "jvdl.id.au",
    . . psa: "usethelatestversion.com"
    }

  3. #3
    SitePoint Addict
    Join Date
    Sep 2003
    Location
    CA
    Posts
    264
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by AussieJohn View Post
    After everything has loaded, (i.e. window.onload), you can assign something to the value of a text field like so:

    Code JavaScript:
    document.getElementById("someTextField").value = "some value";
     
    // in your app, this should do the trick:
    document.getElementById("awf_field-24855776city").value = geoip_city();
    that worked flawlessly! Thank you so much! For anyone who finds this later on here is my complete Javascript:
    Code:
    <script language="javascript">
    
    window.onload=function(){
    document.getElementById("awf_field-24855776city").value = geoip_city();
    }</script>


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
  •