Inserting HTMLInput Element value

Discussion in 'JavaScript' started by cesarcesar, Sep 11, 2008.

  1. #1
    I have a textfield that uses a dynamic dropdown select script to let me choose a country by a few letters. Example, keying "B" shows "Brazil, Bulgaria, Belarus... Once i choose a county another function fires to send the selected data via http_request to another page. Here's it in use.

    <input type="text" name="country" onkeyup="ajax_showOptions(this,'get_country',event)" onblur="makeRequest('insert.php?field_name=country&field_value=',this.value)">
    Code (markup):
    The problem is that the *this.value* in makeRequest() only sends the "B" or whatever chars where entered in the field. Now I understand that the dropdown script is filling the field in a different way than I would have keyed it but how im not sure. Looking at FireBug i think i see that my selection "Brazil" shows under *HTMLInputElement*. I guess my question is how do i get that value to show instead of *this.value* in makeRequest().

    FYI, each script works fine when not working together on the same field.

    Thanks much for the help.
     
    cesarcesar, Sep 11, 2008 IP
  2. zerxer

    zerxer Peon

    Messages:
    368
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Can we see the page you're working with (link to your script)?

    Also, not sure if this will help at all, but I looked at the dynamic dropdown script's page and saw this here and thought it might be something extra you have to use.
     
    zerxer, Sep 11, 2008 IP
  3. cesarcesar

    cesarcesar Peon

    Messages:
    188
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I have linked to the scripts im using. Not much has changed from stock.

    I removed that from the example for space sake. The hidden field could be used... if in new how to get the value from it similar to the drop down.

    I just need to know how to pull the value from the js as its set.
     
    cesarcesar, Sep 11, 2008 IP
  4. zerxer

    zerxer Peon

    Messages:
    368
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    0
    #4
    I wanted to see your script though to see it all implemented so I could see what you need to rip the value from. Well, if you do have the hidden input, and it has an ID like id="whatever_hidden" then you'd do document.getElementById('whatever_hidden') instead of this.value
     
    zerxer, Sep 11, 2008 IP
  5. cesarcesar

    cesarcesar Peon

    Messages:
    188
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #5
    thanks to BrianOConnell and zerxer-

    Solution - replace *this.value* with *document.getElementById('country_hidden').value*.

    The country_hidden element was not in my initial post because i didn't think it was relevant.. bad me. It is shown in the original example linked in my post.
     
    cesarcesar, Sep 12, 2008 IP
  6. cesarcesar

    cesarcesar Peon

    Messages:
    188
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #6
    darn.. found a glitch. the *document.getElementById('country_hidden').value* will not set on the first call of makeRequest(). It will though set if i re-select the drop down value again. Any ideas on hoe to get it to set the first time?
     
    cesarcesar, Sep 17, 2008 IP