Node_Pointer
11-30-2003, 04:25 PM
OK, I have a variable with a value in javascript.
On the same page I also have a form with a text box.
How do I get the value in the javascript variable to appear in the text box?
Help!!!!:) :)
CG-Sparrow
11-30-2003, 04:32 PM
something like:
function yourFunction()
{
var yourVariable;
document.formName.textBoxName.value = yourVariable;
}
have you tried the tutorial on W3 Schools (http://www.w3schools.com) ?
document.formname.fieldname.value = variable;
fredmv
11-30-2003, 04:35 PM
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>untitled</title>
<meta http-equiv="Content-Type" content="application/xhtml+xml; charset=iso-8859-1" />
<script type="text/javascript">
//<![CDATA[
var foo = "bar";
onload = function() { document.forms[0]['t'].value = foo; }
//]]>
</script>
</head>
<body>
<form action="#">
<div>
<label for="t">
Value of <span style="font-family: courier;">foo</span>:
<input type="text" name="t" id="t" />
</label>
</div>
</form>
</body>
</html>
Node_Pointer
11-30-2003, 06:31 PM
Here is my code.
It still does not work. Help me please. THANKS
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><title>Confirmation</title>
<meta content="text/html; charset=iso-8859-1" http-equiv="Content-Type">
<script type="text"/javascript">
var isNN = ( navigator.appName.indexOf( "Netscape" ) != -1 );
var notOk=1;
function autoTab( input,len, e ) {
var keyCode = ( isNN ) ? e.which : e.keyCode;
var filter = ( isNN ) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];
if( input.value.length >= len && !containsElement( filter, keyCode )) {
input.value = input.value.slice( 0, len );
input.form[( getIndex( input ) + 1 ) % input.form.length].focus();
}
return true;
}
function containsElement( arr, ele ) {
var found = false, index = 0;
while( !found && index < arr.length )
if( arr[index] == ele ) {
found = true;
} else {
index++;
}
return found;
}
function getIndex( input ) {
var index = -1, i = 0, found = false;
while ( i < input.form.length && index == -1 )
if ( input.form[i] == input ) {
index = i;
} else {
i++;
}
return index;
}
function myfun(){
var foo = "****";
document.fName.First.value = foo;
}
myfun();
</script>
</head>
<body background="main.jpg">
<p align="center"><font color="#000000" size="7" face="Verdana, Arial, Helvetica, sans-serif">Confirmation</font></p>
<form name="fName" method="post" action="">
<div align="center"> </div>
<table cellpadding="0" cellspacing="0" border="0" width="100%">
<tbody>
<tr>
<td width="50" valign="top"> <font face="Arial"><br>
</font> </td>
<td valign="top" rowspan="1" colspan="1"><font face="Arial" color="#000000">Review the following information.
If there are errors, select the back button to correct them.<br>
When
all information is correct, select the next button to continue.<br>
<br>
</font>
<table align="center" cellpadding="0" cellspacing="0" border="0" width="100%">
<tbody>
<tr>
<td valign="top" nowrap="nowrap"><font face="Arial">Name <br>
<input type="text" name="First" size="20" maxlength="40" readonly="readonly"><br>
<br>
ray326
11-30-2003, 07:11 PM
You can't run something like that in the head because the document doesn't exist at that point, let alone the document's contents.