Inserting HTMLInput Element value

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • empiresolutions
    New Member
    • Apr 2006
    • 162

    Inserting HTMLInput Element value

    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.

    Code:
    <input type="text" name="country" onkeyup="ajax_showOptions(this,'get_country',event)" onblur="makeRequest('insert.php?field_name=country&field_value=',this.value)">
    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 *HTMLInputEleme nt*. 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.
  • Ferris
    New Member
    • Oct 2007
    • 101

    #2
    Hi

    The reason why you get "B" , not "Brazil" , is that "makeReques t" will be execute before the text field changed into "Brazil". So change your code into this:

    Code:
    <input type="text" name="country"
    onkeyup="ajax_showOptions(this,'get_country',event)" 
    onblur=" var _this = this; setTimeout( function(){ makeRequest('insert.php','?field_name=country&field_value='+_this.value); } , 300 );">
    the code will make "makeReques t" executed for 300 ms delay.

    I didn't test my code up there. If the code is not working,post a reply to tell me. :)


    Regards.

    Comment

    • empiresolutions
      New Member
      • Apr 2006
      • 162

      #3
      ferris - I have tried this solution all ready. doesn't work. The timeout only delays the inevitable. Thanks for the time in your suggestions though.

      thanks to BrianOConnell -

      Solution - replace *this.value* with *document.getEl ementById('coun try_hidden').va lue*.

      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.

      Comment

      • Ferris
        New Member
        • Oct 2007
        • 101

        #4
        Originally posted by empiresolutions
        thanks to BrianOConnell -

        Solution - replace *this.value* with *document.getEl ementById('coun try_hidden').va lue*.

        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.

        Brilliant. I think this is the best solution.

        Comment

        • empiresolutions
          New Member
          • Apr 2006
          • 162

          #5
          darn.. found a glitch. the *document.getEl ementById('coun try_hidden').va lue* 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?

          Comment

          • acoder
            Recognized Expert MVP
            • Nov 2006
            • 16032

            #6
            When does this hidden value get set?

            Comment

            • Ferris
              New Member
              • Oct 2007
              • 101

              #7
              Originally posted by empiresolutions
              darn.. found a glitch. the *document.getEl ementById('coun try_hidden').va lue* 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?

              Hi,I test the code, *document.getEl ementById('coun try_hidden').va lue* will return a integer,which means country's ID.

              what do you want to send to insert.php? Country's ID or Country's name?

              Code:
              insert.php?field_name=country&field_value=24
              or

              Code:
              insert.php?field_name=country&field_value=Brazil

              Comment

              Working...