help making picklist auto pick ?? Please

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
rponchek
Forum Newbie
Posts: 7
Joined: Sat Dec 28, 2002 10:33 pm

help making picklist auto pick ?? Please

Post by rponchek »

I am trying to make a picklist automatically pick a user selected option, without hitting a "go" or submit button.

Can this be done with PHP, if not, I hear it can with Java... How do you do this, please help...
User avatar
Elmseeker
Forum Contributor
Posts: 132
Joined: Sun Dec 22, 2002 5:48 am
Location: Worcester, MA

Post by Elmseeker »

I don't think you can use PHP for this, Javascript can do it but I don't know any JScript so I don't know how.
Rob the R
Forum Contributor
Posts: 128
Joined: Wed Nov 06, 2002 2:25 pm
Location: Houston

Post by Rob the R »

Elmseeker is right - Javascript is the way to do this. The way I do it is to utilize the "onChange" method of the picklist (a "select" object in HTML forms parlance) to call a Javascript function that will do what I want right then. The example below loads a new page based on what the user selects from the list.

Code: Select all

<html>
<head>

<script language="Javascript">
<!-- 
   function gotoPage() &#123;
      if (document.selectpage.pagelist.value != "") &#123;
         if (top.main && top.main.document) &#123;
            top.main.document.location.href =
               document.selectpage.pagelist.value + ".html" ;
         &#125;
         else &#123;
            document.location.href = 
              document.selectpage.pagelist.value + ".html" ;
         &#125;
      &#125;
   &#125;
// -->
</script>


</head>

<body>

<form name="selectpage">
<select name="pagelist" onChange="gotoPage();">
  <option value="" disabled>Select from this list</option>
  <option value="page1">First Page</option>
  <option value="page2">Second Page</option>
  <option value="page3">Third Page</option>
</select>
</form>

</body>
</html>
Post Reply