Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder
    Join Date
    Apr 2005
    Location
    austin, tx
    Posts
    148
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Populate Text Box from Javascript

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

    Code:
    <!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>

  • #2
    Senior Coder nikkiH's Avatar
    Join Date
    Jun 2005
    Location
    Near Chicago, IL, USA
    Posts
    1,973
    Thanks
    1
    Thanked 32 Times in 31 Posts
    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;

    If this post contains any code, I may or may not have tested it. It's probably just example code, so no getting knickers in a bunch over a typo, OK? If it doesn't have basic error checking in it, such as object detection or checking if objects are null before using them, put that in there. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
    Bored? Visit
    http://www.kaelisspace.com/

  • #3
    Regular Coder
    Join Date
    Apr 2005
    Location
    austin, tx
    Posts
    148
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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
    Code:
    <!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.
    Last edited by sftl99; 07-01-2005 at 05:22 PM.

  • #4
    Senior Coder nikkiH's Avatar
    Join Date
    Jun 2005
    Location
    Near Chicago, IL, USA
    Posts
    1,973
    Thanks
    1
    Thanked 32 Times in 31 Posts
    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];
    }

    If this post contains any code, I may or may not have tested it. It's probably just example code, so no getting knickers in a bunch over a typo, OK? If it doesn't have basic error checking in it, such as object detection or checking if objects are null before using them, put that in there. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
    Bored? Visit
    http://www.kaelisspace.com/

  • #5
    Regular Coder
    Join Date
    Apr 2005
    Location
    austin, tx
    Posts
    148
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •