By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,466 Members | 1,148 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,466 IT Pros & Developers. It's quick & easy.

Inserting HTMLInput Element value

100+
P: 162
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.

Expand|Select|Wrap|Line Numbers
  1. <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 *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.
Sep 11 '08 #1
Share this Question
Share on Google+
6 Replies


Ferris
100+
P: 101
Hi

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

Expand|Select|Wrap|Line Numbers
  1. <input type="text" name="country"
  2. onkeyup="ajax_showOptions(this,'get_country',event)" 
  3. onblur=" var _this = this; setTimeout( function(){ makeRequest('insert.php','?field_name=country&field_value='+_this.value); } , 300 );">
  4.  
the code will make "makeRequest" 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.
Sep 12 '08 #2

100+
P: 162
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.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.
Sep 12 '08 #3

Ferris
100+
P: 101
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.

Brilliant. I think this is the best solution.
Sep 12 '08 #4

100+
P: 162
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?
Sep 17 '08 #5

acoder
Expert Mod 15k+
P: 16,027
When does this hidden value get set?
Sep 18 '08 #6

Ferris
100+
P: 101
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?

Hi,I test the code, *document.getElementById('country_hidden').value* 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?

Expand|Select|Wrap|Line Numbers
  1. insert.php?field_name=country&field_value=24
or

Expand|Select|Wrap|Line Numbers
  1. insert.php?field_name=country&field_value=Brazil
Sep 19 '08 #7

Post your reply

Sign in to post your reply or Sign up for a free account.