...

View Full Version : Javascript / php form help



Alkaline
07-16-2009, 10: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">
<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



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

ckeyrouz
07-17-2009, 02: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;

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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum