PDA

View Full Version : Javascript OnChange Show / Hide Issues



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

Login.php:



<html>
<head>
<script type="text/javascript">
function showMenu(c) {
if(c=="Yes") {
document.getElementById("lidd").style.display="block";
}
else {
document.getElementById("lidd").style.display="none";
}
}
</script>
<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%;
background-repeat:repeat-y;
background-color:#000000;
}
-->
</style>
</head>
<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>
</tr>
<tr></tr>
<tr>
<td height="459" valign="top" background="images/bgfiller.jpg">&nbsp;</td>
</tr>
<tr>
<div align="center">
<form action="loginmeth.php" method="POST">
<table width="501" height="261" border="0">
<tr>
<td colspan="3">&nbsp;</td>
</tr>
<tr>
<td height="33" colspan="3"><ul>
<strong>Login to Access This League</strong>
</ul></td>
</tr>
<tr>
<td>&nbsp;</td>
<td><div align="right">League ID:</div></td>
<td><label>
<select name="lid" id="lid" onchange="showMenu(this.value)" value="Yes">
<option value="" selected></option>
<option value="77366">In The Trenches-A</option>
</select>
</label></td>
</tr>
<div id="lidd">
<tr>
<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>
</select>
</td>
</tr>
</div>
<tr>
<td>&nbsp;</td>
<td><div align="right">Password: </div></td>
<td><input type="password" name="password" id="password"></td>
</tr>
<tr>
<td>&nbsp;</td>
<td><div align="right">Remember Me?</div></td>
<td><input name="radio" type="radio" id="yes" value="Yes" checked>
Yes
<input type="radio" name="radio2" id="no" value="No">
No</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td><input type="submit" value="Submit"></td>
</tr>
</table>
</form>
<p><br>
</p>
</div></td>
</tr>
<tr>
<td height="33">&nbsp;</td>
</tr>
</table>
<?php include("footer.php"); ?>
</body>
</html>




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



<?php
$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..

--Portwolf

forum_amnesiac
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

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

Submit

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.

forum_amnesiac
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

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

IE:

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.