954,178 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

pass the value to the text box

Hi,

I was using example of autocomplete function from this site:
http://www10.brinkster.com/a1ien51/jsExamples/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 "\n";

Sorry, if all of this is not too clear or is too lame, but it's my first time with javascript.

Thank you.

fikka
Newbie Poster
2 posts since Jul 2005
Reputation Points: 10
Solved Threads: 0
 

UPDATED:
I get theTextBox2 has no properties error.
Please see more detailed below.
Here are the *.php file and the script file:
[PHP]


<?
//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;
}



<?
PRINT "\n";
PRINT "\n";
PRINT "\n";
PRINT "\n";
PRINT "Name:\n";
PRINT "\n";
PRINT "\n";
PRINT "\n";
PRINT "Name2:\n";
PRINT "\n";
PRINT "\n";
PRINT "\n";
PRINT "
\n";
PRINT "\n";
PRINT "\n";
PRINT "

fikka
Newbie Poster
2 posts since Jul 2005
Reputation Points: 10
Solved Threads: 0
 

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>
  <SCRIPT language="JavaScript">

    function loadBox(stuff) {
      document.Form1.TextBox2.value = stuff;
    }

  </SCRIPT>
</HEAD><BODY>
  <FORM name="Form1">
    <INPUT type="textbox" id="TextBox1" value="Stuff here"/>
    <INPUT type="textbox" id="TextBox2" />
    <INPUT type="button" value="Click Me" onclick="loadBox(document.Form1.TextBox1.value)">
  </FORM>
</BODY></HTML>


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">

self.setInterval("doCheck()",5000);

function doCheck() {
  if (document.Form1.TextBox1.value) {
  document.Form1.TextBox2.value = document.Form1.TextBox1.value}
}

</SCRIPT>


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

navyjax2
Junior Poster in Training
53 posts since Jun 2005
Reputation Points: 11
Solved Threads: 1
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You