Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

select boxes????

Status
Not open for further replies.

sanjdhiman

Programmer
Jan 15, 2003
189
GB
I have the following code

<?
echo &quot;<form action=$PHP_SELF?companyname=\&quot;$agentcompany\&quot; method=\&quot;post\&quot; name=\&quot;deleteagent\&quot;>&quot;;
?>
<tr>
<td width=30% class=&quot;form&quot;>Choose by Company Name:</td>
<td width=100% class=&quot;form&quot;><select name=&quot;agentcompany&quot; onChange=&quot;javascript:submit()&quot;>
<option value=&quot;none&quot;>Select</option>

<?
$conn=db_connect();
$query = &quot;SELECT CompanyName FROM estateagent&quot;;
$result = mysql_query($query);
if (mysql_num_rows($result) >0)
$num_results = mysql_num_rows($result);
for ($i=0; $i <$num_results; $i++)
{
$row = mysql_fetch_array($result);
$companyname=$row[&quot;CompanyName&quot;];

echo &quot;<option value=\&quot;$companyname\&quot;> $companyname </option>&quot;;
}
?>
</select>

What i would like to do is that once a person clicks on the dropdown select box it re-evaluates the page and submits itself, and runs a function called

showagentdetails($companyname)

based on the value in the drop down.

I understand that if the SELECT box is geneated by PHP it doesnt evaluate the page everytime..

IS there away to get round this at all?

Regards and thanks in advance


Sanj
 
Try using:

<select name=foobar onChange=document.thisForm.submit()>
<option value=$companyname>$companyname</option>
</select>


When you make a selection it will submit the form.

*make sure you do not have a submit or cancel button.
 
A suggestion:
Write a little JavaScript function in the page that sets a hidden field e.g. 'action'. Set the value of the field to 'showagentdetials' or something like that. This will allow you to know when the script posts what caused the posting.
This way there's no need to forego a submit button if it is needed for the form.
 
Hi there

Ok o tried what BitFuzzy said but still no joy, it takes the value in the URL but does not ouput the info i need.

So im still at step 1



So the code hasnt changed but it does not change the what i see on screen.

when i call the function i call it outside the form tag.


so i ahve the above code abbreviated

<form ....>
<select name= ....>
<option value=$companyname>generated by php
...
</option>
</select>
</form>

showagentdetails($companyname)


The function is declared before all this but shown below



function showagentdetails($companyname)
{
echo $companyname; //this never changes? hence i know the form is not working - the javascript that is
$query=&quot;SELECT *
FROM estateagent
WHERE CompanyName='$companyname'&quot;;

$result=mysql_query($query) or die(&quot;Error in showagentdetails&quot; . mysql_error());
$num_results=mysql_num_rows($result);
$row=mysql_fetch_array($result);

echo &quot;<table width=80% cellspacing=1 cellpadding=1 border=1>&quot;;
echo &quot;<tr><td class=subtitleblack>Company Name: <strong>$companyname</strong></td></tr>&quot;;





Hope that helps

Regards

Sanj
 
SORTED IT

THANKS FOR YOU HELP PPL


when i was calling the function i was not using the <select name&quot;$$$$$&quot;> value was using something else

hehehe
my mistake

Cheers ppl

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top