...

View Full Version : Populate Text Box from Javascript



sftl99
07-01-2005, 05:32 PM
I have a javascript that recalls a number from a text file and displays it. What I want to do is have that number display in the "QuoteNumber" text box by default.

Go to www.jasonpcarroll.com/this.html to see what I'm talking about.

Can I get that text box to automatically populate with the number that is recalled by <script language="Javascript">ccount_display('1')</script>?


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Quote Form</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="Javascript" src="http://www.jasonpcarroll.com/allcomponents/ccount/display.php">
<!--
//-->
</script>
</head>

<body>
<form name="quoteform" method="POST">
QUOTE #:
<script language="Javascript">ccount_display('1')</script>
<br>
<input name="QuoteNumber" type="text" id="QuoteNumber3" value="Quote Number" size="15" onFocus="hlight(this)">
<br>
<input type="submit" value="Submit Form" name="submit" class="sbttn">
<input type="reset" name="Reset" value="Reset Form" class="sbttn">
</form>
</body>
</html>

nikkiH
07-01-2005, 05:38 PM
A number is recalled with ccount_display('1'). But where does it go?
Have the function return the number. Then assign it to the form field.

var count = ccount_display('1');
document.formname.elementname.value = count;

sftl99
07-01-2005, 05:50 PM
I didn't know where to put that code so I tried making it a function that i would body OnLoad...this didn't work. Can you check it out and let me know what I did wrong? Live example is still up HERE (http://www.jasonpcarroll.com/this.html)

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Quote Form</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="Javascript" src="http://www.jasonpcarroll.com/allcomponents/ccount/display.php">
<!--
//-->
</script>
<script language="JavaScript">
var C = ccount_display('1');
function displaycount() {
document.quoteform.QuoteNumber.value = C;
}
</script>
</head>

<body onLoad="displaycount();">
<form name="quoteform" method="POST">
QUOTE #:
<input name="QuoteNumber" type="text" id="QuoteNumber" size="15">
<font color="#999999">&lt;&lt;&lt;This is where I want the above number to display
automatically.</font><br>
<input type="submit" value="Submit Form" name="submit" class="sbttn">
<input type="reset" name="Reset" value="Reset Form" class="sbttn">
</form>
</body>
</html>


The number is being displayed as the entire page instead of inside the QuoteNumber text box. I can't figure out what I did wrong.

nikkiH
07-01-2005, 07:22 PM
Your problem is here.
function ccount_display(id) { document.write(ccount_link[id]);

Document.write wipes out the content of the page if used in certain ways.
I try to never use it, personally.

You wanted:
function ccount_display(id)
{
return ccount_link[id];
}

sftl99
07-01-2005, 08:16 PM
Perfect! Dummy me, I didn't even think to look there, I thought there was something wrong with my main page, not with the linked javascript.

Thanks to everyone!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum