Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 02-14-2003, 10:06 AM   #1 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,530
sde is on a distinguished road
dynamic select menues

i have a form:
- 1 select menu
- 2 radio buttons

i would like the select box to show a different list depending on what radio box is checked.

lets say i have a bunch of people broken up into many groups.

sde, admin, revolution, bdl

sde and admin are in group 1, and revolution and bdl are in group 2.

examle:
PHP Code:
<form method=post action=somepage.html>
Select from: <input type=radio name=display value=allAll <input type=radio name=display value=somegroup 1

<br>

<
select name=names>
<
option>--- dynamic names go here -- </option>
</
select>

</
form
with this code, and without refreshing the page, i would like the options in the select box to toggle between all 4 names, and just the 2 in group 1.

this has to be javascript , and i'm sure i have to define the arrays above somewhere, but i'm not sure how.

can anyone help me out?
sde is offline   Reply With Quote
Old 02-14-2003, 03:17 PM   #2 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,530
sde is on a distinguished road
i got a script that i customized, but now i'm seeing a problem.

the select box changes dynamically, but
there are no values in it to submit. i need the
script to be able to send variables via the POST
method depending on what option the user
selects.

here's a copy of my page, .. any ideas?
PHP Code:
<html>
<head>
<title>Dynamic Select Box Generation</title>
    
<script language="JavaScript">

var array1 = null;
var array2 = null;

var active = new Array();
  active[0] = "Joe Schmoe";
  active[1] = "John Dough";
  active[2] = "Jack Smith";
  
var active_id = new Array();
  active_id[0] = "23";
  active_id[1] = "45";
  active_id[2] = "5";

var inactive = new Array();
  inactive[0] = "Johnny Five";
  inactive[1] = "Jordon Whiley";
  
var inactive_id = new Array();
  inactive_id[0] = "14";
  inactive_id[1] = "38";
  
    
function loadbox2(){

  //clearing loop
  var box2 = document.form1.agents.options;
  for (i = 2; i < document.form1.agents.options.length; i++){
    box2[i].text = "";
    box2[i].value = "";
  }//ends clearing FOR loop

  //begins radio search
  for (counter=0; counter < 2; counter++){
    if (document.form1.filter[counter].checked == true){
      var choice = document.form1.filter[counter].value;
    }//ends IF
  }//ends for

  if (choice =="active"){
    array1 = active;
  }//ends first (active) IF

  if (choice == "inactive"){
    array1 = inactive;
  }//ends second (inactive) IF

  var box2 = document.form1.agents.options;

  //clearing loop
  for (i = 2; i < document.form1.agents.options.length; i++){
    box2[i].text = "";
    box2[i].value = "";
  }//ends clearing FOR loop

  for (i = 0; i < array1.length; i++){
  box2[i + 2].text = array1[i];
  }// ends populating FOR
}//ends population function

</script>

</head>

<body bgcolor="#ffffff" text="#000000">

<form method=POST action=<?=$PHP_SELF?> name="form1">

Filter:
<input type="radio" name="filter" value="active" onClick="loadbox2()">active <input type="radio" name="filter" value="inactive" onClick="loadbox2()">inactive

<br><br>
Agents:<br>
<select name="agents">
<option>-- Select an Agent to Edit --
<option>
<script lanugage="JavaScript">
for (count=0; count < active.length; count++){
document.write("<option>");}
</script>
<option>
</select>

<input type=submit>

</form>

<?
echo $agents;
?>
</body>
</html>
sde is offline   Reply With Quote
Old 02-14-2003, 03:19 PM   #3 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,530
sde is on a distinguished road
i forgot to mention, .. i would like to have the
active_id[] and inactive_id[] the information
that gets submitted in the form when the user
selects a specific user.
sde is offline   Reply With Quote
Old 02-14-2003, 10:09 PM   #4 (permalink)
saline
I am red.
 
saline's Avatar
 
Join Date: Feb 2003
Location: Cleveland, OH
Posts: 139
saline is on a distinguished road
talking to yourself

You seem to be talking to yourself here.

It's an interesting problem to be sure but I'm not entirely sure what you have accomplished or not. Could you be more clear on what working and what you still need to get done?

As for submitting with different types (post and get) you might want to make a normal button the "submit" button which calls another function to determine what information the user has selected. Then depending on whether this information needs to be sent post or get, have the script click appropriate, but hidden (with css) submit button. You might need to fill in invisible form elements before clicking submit through the script. So you would have three forms, the dummy form that users see, and a post and a get form which would be seruptitiously filled and then sent when the user clicks the dummy submit button.

Why would you need to send the information one way over the other, why not just make it post and be done with it?
saline is offline   Reply With Quote
Old 02-14-2003, 10:43 PM   #5 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,530
sde is on a distinguished road
thanks for your thoughts saline =) that surely takes the blinders off. i can see how i can work with it to populate hidden input fields to send the id i need.

here's what i'm trying to do. i've created a web application for a tech support call center to track calls and employee production.. it also ties into online knowledge base, and other company related things.

it has been up and running for nearly a year now, and now i am working on a new version. my primary goal is to streamline the back-end.

this little bit of code is for the administrative or management level of access to add / edit agents ( the employees entering data )

currently i have a select box populated by all agents. ( active and inactive ) . i want the user to be able to choose with the radio buttons if they want a drop down list of active, or inactive agents to edit.

i could do it with php only, but that would require them to submit the page once more. so i'm going to use php to generate the javascript arrays for a more graceful interface.

why do i need to submit other information that what the user is viewing?
-- good question. the user needs to see the agent's full name to decide who to edit. to streamline my code and assure efficient data retrieval, i choose to identify each agent by an integer that is their unique id. this is why i need to pass the 'id' data .. i could care less about the names being sent.
Code:
<option value=245> Joe Schmoe </option>
that is the effect i'm trying to get, but i don't think it is possible. now with your hidden input field suggestion, i think i have a place to start again.

thanks!
sde is offline   Reply With Quote
Old 02-15-2003, 10:05 AM   #6 (permalink)
saline
I am red.
 
saline's Avatar
 
Join Date: Feb 2003
Location: Cleveland, OH
Posts: 139
saline is on a distinguished road
excellent

I'm glad I could help, I was wondering if anything I wrote at one in the morning was going to be coherent let alone useful.

Good Luck.
saline is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
EMERGENCY: Dynamic form processing DavH27 PHP 8 10-27-2004 08:52 PM
Nested subquery within the Select clause jsze Everything SQL ( MySQL, MSSQL, DB2, Postgre, Oracle, etc...) 6 10-12-2004 11:23 AM
dynamic allocation..urgent help needed!!! kashif Standard C, C++ 4 04-21-2003 09:50 AM


All times are GMT -8. The time now is 01:09 AM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0 RC8 ©2007, Crawlability, Inc.





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting