View Full Version : Javascript OnChange Show / Hide Issues

06-16-2009, 03:27 PM
Ok so I have a file called Login.php

What I need this to do is when a user selects League ID: ITT-A (or any other option) it will use the onchange function and show the next select menu that has the user names for that specific group (ITT-A in the example)

This is what I have so far:


<script type="text/javascript">
function showMenu(c) {
if(c=="Yes") {
else {
<title>In The Trenches</title>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
<style type="text/css">
body {
background-image: url("images/bg.JPG");
background-position: 50% 50%;
<body bgcolor=#ffffff leftmargin=0 topmargin=0 marginwidth=0 marginheight=0>
<?php include("header.php"); ?>
<td height="27" valign="top" background="images/bgfiller.jpg">&nbsp;</td>
<td height="459" valign="top" background="images/bgfiller.jpg">&nbsp;</td>
<div align="center">
<form action="loginmeth.php" method="POST">
<table width="501" height="261" border="0">
<td colspan="3">&nbsp;</td>
<td height="33" colspan="3"><ul>
<strong>Login to Access This League</strong>
<td><div align="right">League ID:</div></td>
<select name="lid" id="lid" onchange="showMenu(this.value)" value="Yes">
<option value="" selected></option>
<option value="77366">In The Trenches-A</option>
<div id="lidd">
<td width="54">&nbsp;</td>
<td width="191" align="right">Login As:</td>
<td width="234">
<select name="fid" id="fid">
<option value="0000">Commissioner</option>
<option value="0001">Franchise 1</option>
<option value="0002">Franchise 2</option>
<option value="0003">Franchise 3</option>
<option value="0004">Franchise 4</option>
<option value="0005">Franchise 5</option>
<option value="0006">Franchise 6</option>
<option value="0007">Franchise 7</option>
<option value="0008">Franchise 8</option>
<option value="0009">Franchise 9</option>
<option value="0010">Franchise 10</option>
<td><div align="right">Password: </div></td>
<td><input type="password" name="password" id="password"></td>
<td><div align="right">Remember Me?</div></td>
<td><input name="radio" type="radio" id="yes" value="Yes" checked>
<input type="radio" name="radio2" id="no" value="No">
<td><input type="submit" value="Submit"></td>
<td height="33">&nbsp;</td>
<?php include("footer.php"); ?>

This is the Loginmeth.php that the form action calls:

$lid = $_REQUEST['lid'];
$fid = $_REQUEST['fid'];
$pass = $_REQUEST['password'];
$rem = $_REQUEST['remember'];

echo "<script type=\"text/javascript\"> window.location = \"http://football4.myfantasyleague.com/2009/login?L=77366&LEAGUE_ID=$lid&FRANCHISE_ID=$fid&PASSWORD=$pass&REMEMBER=$rem\" </script>"


What this login is for is a fantasy football league, and my client wants the login function to come from his website and submit through the form to the league manager (that we do not host) so this is the only way i could think of doing this without spending alot of time on it. But now i am having issues with the forms.

Eventually the username list will get too big so this is why i have to use this function so they can select there league ID>Username(this comes up after they select here league ID)>Password

The form works fine other than this issue..

Can anyone point me in the right direction with this?

Thank you for your time..


06-16-2009, 04:21 PM
I'm not 100% certain I understand what you're looking for, but here goes.

I assume that all the login details are stored in a database.

When a League Name has been entered you could autopopulate a SELECT box with all the usernames for that league.

I have done something similar, on a single page and not requiring the form to be submitted, by first creating an array from the table which includes League_Name, Member_Name, ID, etc., League_Name first

Convert the PHP array to a javascript array and sort it.

When the League name is entered create a function that extracts from the array all lines that match the selected League and use those lines to autopopulate the SELECT box.

There are plenty of scripts that will autopopulate a SELECT box.

Sorry if I haven't addressed what you're trying to do

06-18-2009, 05:00 PM
No the login credentials arent in a database (atleast they arent in a database that we control, they are in a 3rd party database that we have no control over other than creating users / passwords etc)

So this is the general idea:

Select League ID: [ITT-A] > (Onchange depending on selection IE:ITT-A it SHOWS / HIDES the username field of all the users within that league.)
Select Username: [TestName] > (This comes up once League ID is selected SHOWING all the users within that league)
Type Password: [Password] > (They then type there password we generated for them)


then my script redirects them and logs them in automatically. The part i am having issues with is the "Select League ID:" I cant get the onchange function to SHOW / HIDE the usernames for the selected league.

06-19-2009, 07:10 AM
If you have access to the database, then the easiest way to do this would be to use an autopopulate method to first populate the league SELECT box and on a selection autopopulate the users SELECT box.

This is a dynamic way to ensure that all appropriate usernames, for a specific league, are shown in the dropdown.

I have assumed from your post that you at least have access to the database to be able to create usernames and passwords.

There are some PHP scripts out there, using AJAX, that do this

06-19-2009, 02:18 PM
The auto population isnt the issue here. The issue is getting the League ID: onchange function to work properly.

I can do the auto population just fine. The only thing im having issues with is the league ID onchange function to show / hide the username select field.


Select League ID: ITT-A > Onchange Show Username Select Field for that specific league (ITT-A in this example)

I am more than happy to have this done manually for now eventually when i build the admin panel i will integrate some sort of autopopulate function.