View Full Version : Javascript / php form help

07-16-2009, 11:06 PM
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

<form method="POST" action="javascript:insertText('license', 'client' );" onClick="void(0)">
<div align="center">
<b><font color="#99CC00">Generate Client License</font></b>
<table width="300" border="0" align="center" cellpadding="2" cellspacing="0">
<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);
// 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>");

print("<option value=\"\">No clients created yet</option>");
<th height="140">License</th>
<td><textarea name="license" rows="7" readonly="readonly" id="license"></textarea></td>
<br />
<td><input type="submit" value="Submit">

the javascript function

<script type="text/javascript">
function insertText(form, client){

syn_id = document.getElementById(client).value
website = document.getElementById(client).options[syn_id].text


07-17-2009, 03:43 PM
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;