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 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Jul 2009
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Javascript / php form help

    Alright so here is what I have, I have a drop down box that lists clients from a mysql database. from this database I need two things, website and syn_id. I have the syn_id as the value and the website as the text. Then on the action of the form, I have it go to a java script function that outputs text to a text box based on the selection. However, this only works for the first two. That is where I'm stuck. Here is the code.

    The form
    Code:
    <form method="POST" action="javascript:insertText('license', 'client' );" onClick="void(0)">
                    <div align="center">
                        <center>
                            <p>
                                <b><font color="#99CC00">Generate Client License</font></b>
                          <table width="300" border="0" align="center" cellpadding="2" cellspacing="0">
                                        <tr>
                                            <th width="124">Client</th>
                                            <td width="168">
                                                
                                                <select name="client" size="1" id="client">
                                                    <script language="php">
                                                        $website = "SELECT website,syn_id FROM SynCMSclients ORDER BY syn_id";
    						     $result = mysql_query($website, $link);
                                                        if(mysql_num_rows($result)) 
                                                        {
                                                            // we have at least one user, so show all users as options in select form
                                                            while($web = mysql_fetch_row($result))
                                                            {
                                                                print("<option value=\"$web[1]\">$web[0]</option>");
    															
                                                            }
                                                        }
                                                        else 
                                                        {
                                                            print("<option value=\"\">No clients created yet</option>");
                                                        }
                                                    </script>
                                                </select>
                                            </td>
                                        </tr>
                                        <th height="140">License</th>
                                        <td><textarea name="license" rows="7" readonly="readonly" id="license"></textarea></td>
                                        <br />
                                        <tr>
                                            <td>&nbsp;</td>
                                            <td><input type="submit" value="Submit">
                                        </tr>
                          </table>
                                </p>
                      </center>
      </div>
                    </form>

    the javascript function

    Code:
     <script type="text/javascript">
    function insertText(form, client){
    	
    syn_id = document.getElementById(client).value
    website = document.getElementById(client).options[syn_id].text
    
    document.getElementById(form).innerHTML=syn_id;
    }
    </script>

  • #2
    Senior Coder ckeyrouz's Avatar
    Join Date
    Jun 2009
    Location
    Montreal, Canada
    Posts
    1,044
    Thanks
    5
    Thanked 179 Times in 179 Posts
    try this:
    <script type="text/javascript">
    function insertText(form, client)
    {
    var zObj = document.getElementById(client).value;
    syn_id = zObj[zObj.selectedIndex].value;
    website = zObj[zObj.selectedIndex].innerHTML;

    document.getElementById(form).innerHTML=syn_id;
    }
    </script>


  •  

    Posting Permissions

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