•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the JavaScript / DHTML / AJAX section within the Web Development category of DaniWeb, a massive community of 423,758 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,253 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JavaScript / DHTML / AJAX advertiser: Lunarpages Web Hosting
Views: 884 | Replies: 4 | Solved
![]() |
•
•
Join Date: Apr 2008
Posts: 4
Reputation:
Rep Power: 0
Solved Threads: 0
Hi all!
I have two functions, one which calls the other (here simplified) that are part of an autocomplete process. The scripts run without error, however the part I am posting here returns "undefined" for one of my variables. The alert in the function findValue() returns the correct "thisID" in the alert, however the function fillCodes() that called it returns "undefined" in its alert:
Anybody have a clue?
Sandra
I have two functions, one which calls the other (here simplified) that are part of an autocomplete process. The scripts run without error, however the part I am posting here returns "undefined" for one of my variables. The alert in the function findValue() returns the correct "thisID" in the alert, however the function fillCodes() that called it returns "undefined" in its alert:
function findValue(li) {
if( !!li.extra ) var thisID = li.extra[0];
alert(thisID);
return thisID;
}
function fillCodes() {
var oSuggest = $("#my_input_field")[0].autocompleter;
var thisID = oSuggest.findValue();
alert(thisID);
}Anybody have a clue?
Sandra
•
•
Join Date: Apr 2005
Location: New York state
Posts: 465
Reputation:
Rep Power: 5
Solved Threads: 72
•
•
Join Date: Apr 2008
Posts: 4
Reputation:
Rep Power: 0
Solved Threads: 0
•
•
•
•
You're never passing an argument to the findValue function. findValue requires an argument but it is never receiving one.
findValue() is finding and alerting the correct ID - it just does not return a value.
I just learned that the findValue() function (jQuery plugin for suggest) is asynchronous and needs the event handler onFindValue() to be defined.
But I dont know how to do this
Sandra
•
•
Join Date: Apr 2008
Posts: 4
Reputation:
Rep Power: 0
Solved Threads: 0
Ok, clearly nobody knows how to define an event handler or use jQuery.
Since I don't know either, I have tried another approach.
First I created a hidden field with the name of "id_holder". I also have an input field where I want the returned value to be displayed named "id_target".
Then I changed my findValue() function to:
Now my calling function is:
Now the curious thing is that the first alert is empty, while the second identical alert displays the correct id value. If the script does not contain at least one alert, then id_target remains empty.
Can anybody offer a solution as to how I can make this work without an alert? What is actually happening between the first and second alert?
If you are wondering why I don't put it all within the findValue() function, its because the final fillCodes() function will contain a loop to populate fields by sequence (the above code is simplified to make it easy to read).
Sandra
Since I don't know either, I have tried another approach.
First I created a hidden field with the name of "id_holder". I also have an input field where I want the returned value to be displayed named "id_target".
Then I changed my findValue() function to:
function findValue(li) {
if( li == null ) return alert("No match!");
if( !!li.extra ) var sValue = li.extra[0];
document.my_form.id_holder.value = sValue;
}Now my calling function is:
function fillCodes() {
var oSuggest = $("#my_input_field")[0].autocompleter;
oSuggest.findValue();
var this_holder = eval("document.my_form.id_holder");
var this_target = eval("document.my_form.id_target")
alert(this_holder.value);
alert(this_holder.value);
this_target.value = this_holder.value
} Now the curious thing is that the first alert is empty, while the second identical alert displays the correct id value. If the script does not contain at least one alert, then id_target remains empty.
Can anybody offer a solution as to how I can make this work without an alert? What is actually happening between the first and second alert?
If you are wondering why I don't put it all within the findValue() function, its because the final fillCodes() function will contain a loop to populate fields by sequence (the above code is simplified to make it easy to read).
Sandra
Last edited by SandraC : Apr 4th, 2008 at 12:01 pm.
![]() |
•
•
•
•
•
•
•
•
DaniWeb JavaScript / DHTML / AJAX Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Similar Threads
- passing data from one function to another in C (C)
- Regarding Function Returning a Value. (C)
- Exact meaning of functions returning reference (C++)
- Having trouble passing bool type to function....need help (C++)
- Help function not returning correct value (C++)
- How to declare this function? (C)
Other Threads in the JavaScript / DHTML / AJAX Forum
- Previous Thread: image breaking
- Next Thread: image verification


Linear Mode