/    Sign up×
Community /Pin to ProfileBookmark

Inserting HTMLInput Element value

I have a textfield that uses a [URL=”http://www.dhtmlgoodies.com/index.html?whichScript=ajax-dynamic-list”]dynamic dropdown select script[/URL] 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 [URL=”http://www.captain.at/howto-ajax-form-post-get.php”]via http_request[/URL] 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)”>[/CODE]

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.

to post a comment

8 Comments(s)

Copy linkTweet thisAlerts:
@toicontienSep 11.2008 — Most likely when you type "B" in the field, then choose the country from the list, the text box is losing focus, and therefor fires the onblur event and executing a call to makeRequest. Instead of onblur, you need some sort of event for when you choose something from the dynamic drop down select.
Copy linkTweet thisAlerts:
@cesarcesarauthorSep 11.2008 — yes i understand when/why its calling. my question is how to set the this.value to the correct value. my JS is not so strong but i know its there somewhere.
Copy linkTweet thisAlerts:
@toicontienSep 11.2008 — The reason it's not the correct value is because makeRequest() is executing too soon. Does the dynamic drop down script have a way to specify a function that should be executed when the user selects something from the dynamic drop down? It's in this "custom event", of sorts, that you need to call makeRequest().
Copy linkTweet thisAlerts:
@toicontienSep 11.2008 — Looking at the page, it doesn't appear to have any way to execute code once the user has selected something.
Copy linkTweet thisAlerts:
@cesarcesarauthorSep 12.2008 — toicontien - thanks for your time in replies.

thanks to BrianOConnell -

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.
Copy linkTweet thisAlerts:
@toicontienSep 12.2008 — Ah, ok. ? Glad you got it figured out.
Copy linkTweet thisAlerts:
@cesarcesarauthorSep 17.2008 — 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?
Copy linkTweet thisAlerts:
@toicontienSep 18.2008 — Can you post the HTML and JavaScript you are using?


Help @cesarcesar spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 11.29,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ

legal: ({
terms: of use,
privacy: policy
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
recent_tips: (
tipper: @bahaedd,
tipped: article
amount: 1000 SATS,

tipper: @Balmasexy,
tipped: article
amount: 1000 SATS,

tipper: @mbsaad,
tipped: article
amount: 1000 SATS,