![]() |
| ||
| pass the value to the text box Hi, I was using example of autocomplete function from this site: http://www10.brinkster.com/a1ien51/j...typeAhead.html But I have to change it a little bit, so there is a question: I have 2 text boxes - theTextBox1, theTextBox2 and 1 array ar = new array ([“xxx1�,�yyy1�],[“xxx2�,�yyy2�],[“xxx3�,�yyy3�]); both xxx* and yyy* are text elements. First of the text boxes uses this autocomplete code and gets the xxx* value. It works fine, But I also need, to set up theTextBox2 value with yyy* if theTextBox1 get any of xxx* values. I have the variable, which gets the right yyy value from the aaray, but don't know how pass this value to the textbox. This doesn't work: .... var theTextBox2 = document.Form1.name1; // theTextBox2 variable is already set up and has the right value. ... PRINT "<INPUT TYPE=text NAME=\"name1\" VALUE=\"$name1\">\n"; Sorry, if all of this is not too clear or is too lame, but it's my first time with javascript. Thank you. |
| ||
| Re: pass the value to the text box UPDATED: I get theTextBox2 has no properties error. Please see more detailed below. Here are the *.php file and the script file: [PHP] <html> <head> <style type="text/css"> ... </style> <? //fill the theOptions array with the values form the database ?> //How String Should Match var ignoreCase = true; //Ignore upper and lower cases var matchAnywhere = false; //Match pattern anywhere is string //Match TextBox Width var matchTextBoxWidth = true; //False uses CSS value in div.spanTextDropdown //Visible Time for options menu to be open when untouched var theVisibleTime = 1500; //Show Matching Data Message var ShowNoMatchMessage = true; var noMatchingDataMessage = "No Matching Data"; var theTextBox2; //Use Timeout var useTimeout = false; //false uses onblur //Add reference to the element you want to add this too. function addHandler() { document.Form1.name.onkeyup = GiveOptions document.Form1.name.onblur = StartTimeout; if(navigator.userAgent.toLowerCase().indexOf("opera") != -1)document.Form1.name.onkeypress = GiveOptions; //Fix for Opera! var theTextBox2 = document.Form1.name2; } </script> <!-- Reference the JavaScript File --> <script type="text/javascript" src="autocomplete.js"></script> </HEAD> <? PRINT "<body BGCOLOR=\"SILVER\" onload=\"addHandler()\">\n"; PRINT "<FORM NAME=\"Form1\" AUTOCOMPLETE=\"off\" METHOD=\"POST\" ACTION=\"whatever.php\">\n"; PRINT "<TABLE>\n"; PRINT "<TR>\n"; PRINT "<TD>Name:</TD>\n"; PRINT "<TD><INPUT TYPE=text NAME=\"name\" VALUE=\"$name\"></TD>\n"; PRINT "</TR>\n"; PRINT "<TR>\n"; PRINT "<TD>Name2:</TD>\n"; PRINT "<TD><INPUT TYPE=text NAME=\"name2\" VALUE=\"$name2\"></TD>\n"; PRINT "</TR>\n"; PRINT "</TABLE>\n"; PRINT "<BR>\n"; PRINT "<INPUT TYPE=submit VALUE=\"OK\">\n"; PRINT "</FORM>\n"; PRINT "</HTML>\n"; [/PHP] var regExFlags = ""; |
| ||
| Re: pass the value to the text box I'm not sure if you still need this solved or not - this is an old post and came across it while looking for something completely unrelated, but in any event, I think I might have a solution you can try to implement: <HTML><HEAD><TITLE>TEST</TITLE> Not sure if it'll help, but it copies text from one textbox to the next with an 'onclick' event of a button. You pasted way too much code for me to go through to figure out if what you are trying to do is done on an interval or what (next time, just the applicable code you are trying to fix might be ok, or simplify it down to something like what I have above), as I'm not a PHP guy and hate the language, personally (it's just JavaScript on crack and I'd rather stick with the simpler, CLIENT-SIDE, and therefore FASTER code), but I would just tell you that you should probably just add the contents of the first textbox to the second at the same time as you do the first box. Just, within the same function that populates the first box, tell it to do a document.Form1.TextBox2.value = variable (and variable equals the same variable as the text that #1 got), rather than try to do some sort of poll of the box for when it gets populated. You could do that, though, if you really, really need to. Use "setInterval" and have it run a function every how-ever-often you need to - it would look something like this: <SCRIPT language="JavaScript"> That will check the box every 5 seconds for a value and send it to the 2nd box when populated. Only thing is, if you want it to stop at some point, you'll need a clearInterval in there, but you'll have to figure out what event you want to trigger that. Cheers, Tom |
| All times are GMT -4. The time now is 1:42 am. |
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC