3 Replies - 1385 Views - Last Post: 17 October 2006 - 06:35 PM

#1 Arenlor  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 34
  • View blog
  • Posts: 389
  • Joined: 26-April 06

How to use JavaScript and select to create dropdown box

Posted 17 October 2006 - 12:54 PM

Ok Here is what I have down so far, just can't figure out how to get this form to work correct.
echo "<form method=\"get\" name=\"user\" action=\"$PHP_SELF\">
<select name=\"member_id\" id=\"member_id\" onchange=\"document.user.member_id.options[document.user.member_id.selectedIndex].value\" >";
for($i = 0; $i < $namenum; $i++)
{
$row = mysql_fetch_array($supplyname);
if($i != 3)
{
echo "<option value=\"$row[0]\">$row[1] $row[2]</option>";
}
else
{
echo "<option value=\"\"></option>";
}
}
echo "</select></form>";


And yes I'm trying to mix PHP and Javascript.

Is This A Good Question/Topic? 0
  • +

Replies To: How to use JavaScript and select to create dropdown box

#2 Amadeus  Icon User is offline

  • g+ + -o drink whiskey.cpp
  • member icon

Reputation: 248
  • View blog
  • Posts: 13,506
  • Joined: 12-July 02

Re: How to use JavaScript and select to create dropdown box

Posted 17 October 2006 - 04:24 PM

Can you elaborate on what the problem is?
Was This Post Helpful? 0
  • +
  • -

#3 Arenlor  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 34
  • View blog
  • Posts: 389
  • Joined: 26-April 06

Re: How to use JavaScript and select to create dropdown box

Posted 17 October 2006 - 06:23 PM

The form's supposed to send the value back when selected. I have no clue how to do that, nor if I even have the onchange thing correct.
Was This Post Helpful? 0
  • +
  • -

#4 snoj  Icon User is offline

  • Married Life
  • member icon

Reputation: 84
  • View blog
  • Posts: 3,564
  • Joined: 31-March 03

Re: How to use JavaScript and select to create dropdown box

Posted 17 October 2006 - 06:35 PM

You mean like what Megatokyo's dropdown list of comics works?

Basically what you're doing with the Javascript is set the value of member_id....something that is done already when you select something. So it's pointless to set it manually.

Really what you do with "onchange" in this situation is take the selected index and get something elsewhere in the document, redirect the user someplace, or even make an XML request.


Also, you can't "mix" PHP and Javascript. PHP outputs text that is then parsed by the HTML browser as Javascript. Javascript can then be used to send requests to an HTTP server and that server then runs the request (which can be a PHP script).
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1