Results 1 to 3 of 3

Thread: [RESOLVED] calling java script function with form data

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2003
    Posts
    259

    Resolved [RESOLVED] calling java script function with form data

    i have an function in a js page that i call with an onclick event in a html form like this. its called showcolorgrid2

    <input type="button" onclick="showColorGrid2('menucolor','sample_1');" value="Menu Color">&nbsp;<input name="menucolor" type="text" id="menucolor" size="9" value="<?php echo $menucolor; ?>"> &nbsp;<input type="text" ID="sample_1" size="1" value="">

    when you click the button it loads the sample_1 field with the color of the hex value that is populated in menucolor field. so menucolor has the hex value in text and the sample_1 is colored in as the color. it works fine but since i populate it from a database with php with the current value i would like to be able to when the form loads have the sample_1 show the color. right now its blank until the user clicks the button.

    how can i call that function with the value of menucolor when the page loads?

  2. #2
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    Re: calling java script function with form data

    use window.onload:
    Code:
    <script language="javascript">
      window.onload = function(){
    
        // Update the textbox
        showColorGrid2('menucolor', 'sample_1');
    
      };
    </script>
    you could also do this with PHP and place a value inside the sample_1 text box when loading the information from the database.
    Like Archer? Check out some Sterling Archer quotes.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2003
    Posts
    259

    Re: calling java script function with form data

    thanks for the idea on using php. i used it for the other part but never thought of using it again. this is what i did

    Code:
    <input type="button" onclick="showColorGrid2('menucolor','sample_1');" value="Menu Color">&nbsp;<input name="menucolor" type="text" id="menucolor" size="9" value="<?php echo $menucolor; ?>">			&nbsp;<input name="sample_1" type="text" id="sample_1" size="1" value="" style="background-color:<?php echo $menucolor; ?>">
    the bold part makes the back color of the text the color that the user has chosen

Posting Permissions

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



Click Here to Expand Forum to Full Width