SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Wizard ryanhellyer's Avatar
    Join Date
    Oct 2006
    Location
    New Zealand
    Posts
    2,323
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Populating multiple input fields with one click

    Hi,
    The following code grabs the code from the select box and dumps it into the input field called "bla".

    Code HTML4Strict:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head profile="http://gmpg.org/xfn/1">
       <title>PixoPoint.com</title>
       <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
       <script type="text/javascript">function process(val, id) {document.getElementById(id).value = val;}</script>
    </head>
    <body>
     
    <form method="post" action="" name="tcp_test">
    <input type="hidden" name="action" value="update" />
    <p>
    	<select name="stuff" onchange="process(this.value, 'bla')">
    		<option value="">Make a selection</option>
    		<option value="shadow">shadow</option>
    		<option value="dark">dark</option>
    	</select>
    	<input type="text" name="bla" value="bla" id="bla" />
    	<input type="text" name="bert" value="bert" id="bert" />
    </p>
    </form>
     
    </body>
    </html>

    Do any of you know a way to use a single select box to populate multiple input fields, each with different data? Or perhaps another method (without select boxes) which would do the same thing? ie: I need to populate both the 'bla' and 'bert' input fields in the code above with only a single click.

    A small app I'm trying to build at the moment will be a lot simpler for the end users if I can populate a range of input fields with a single click.

    thanks

    EDIT: Darn, I posted this in the wrong board. This was supposed to be in the Javascript board. I wonder if I can report my own post?

  2. #2
    SitePoint Author silver trophybronze trophy
    wwb_99's Avatar
    Join Date
    May 2003
    Location
    Washington, DC
    Posts
    10,625
    Mentioned
    4 Post(s)
    Tagged
    0 Thread(s)
    Or some kindhearted advisor will stumble upon your post and move it as appropriate. Carry on.

  3. #3
    SitePoint Wizard ryanhellyer's Avatar
    Join Date
    Oct 2006
    Location
    New Zealand
    Posts
    2,323
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm guessing from the silence that this is not possible

  4. #4
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You could just call the function multiple times.
    Code:
    <select name="stuff" onchange="process(this.value, 'bla'); process(this.value, 'bert')">
    Or modify the function to accept multiple ids
    Code:
    function process(val, ids) {
        for (var i=0, m=ids.length; i<m; i++) {
            document.getElementById(ids[i]).value = val;
        }
    }
    // process(this.value, ['bla', 'bert', 'foo', 'bar'])


Bookmarks

Posting Permissions

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