Jump to content
xisto Community
Sign in to follow this  
sonesay

Grabbing Post Var From <select Mulitple

Recommended Posts

First off im not sure if it goes in PHP or xhtml section this code deals with both. I have 2 pages there is a button on the first that opens a new window and displays 2 select forms. Once selections have been made when you submit it gets submited to first main window and the second window is closed. Im having trouble trying to grab the selected options.

note: the output of the options are from my database so maybe you can fill them with dummy options when you do testing.


groups_index.php

	echo $_POST['group2'];
}


?> linenums:0'><script LANGUAGE="JavaScript">window.name="main_index";function openFormWindow(){ OpenWindow=window.open("groups.php", "newwin", "height=250, width=400,toolbar=no,scrollbars=no,menubar=no,location=no, resizable=no");}</SCRIPT><input type="button" onclick="openFormWindow();" value="Open Form" /><?phpif (isset($_POST['group2'])) { echo $_POST['group2'];}?>
groups.php

function addUser(toGroup,fromGroup) {
var listLength = document.getElementById(toGroup).length;
var selItem = document.getElementById(fromGroup).selectedIndex;
var selText = document.getElementById(fromGroup).options[selItem].text;
var selValue = document.getElementById(fromGroup).options[selItem].value;
var i; var newItem = true;
for (i = 0; i < listLength; i++) {
if (document.getElementById(toGroup).options.text == selText) {
newItem = false; break;
}
}
if (newItem) {
document.getElementById(toGroup).options[listLength] = new Option(selText, selValue);
document.getElementById(fromGroup).options[selItem] = null;
}
}

function saveGroup() {
var strValues = "";
var boxLength = document.getElementById('grouplist2').length;
var elcount = 0;
if (boxLength != 0) {
for (i = 0; i < boxLength; i++) {
if (elcount == 0) {
strValues = document.getElementById('grouplist2').options.value;
} else {
strValues = strValues + "." + document.getElementById('grouplist2').options.value;
}
elcount++;
}
}
if (strValues.length == 0) {
document.forms['groupsform'].submit();
} else {
document.forms['groupsform'].group_users.value = strValues;
document.forms['groupsform'].submit();
}
}
</script>


<form name="groupsform" method="post" action="groups_index.php" target="main_index" onsubmit="setTimeout('window.close()',1000)">
<div align="center">

<select multiple='multiple' size='10' id='group1' name='group1' style='width linenums:150'><?php// include database fileinclude("../includes/database_itrap.php");// get list of members $m_query = "SELECT userid, username FROM users";$m_result = mysql_query($m_query, $link) or die("Cannot return users list");?><script type='text/javascript'>function addUser(toGroup,fromGroup) { var listLength = document.getElementById(toGroup).length; var selItem = document.getElementById(fromGroup).selectedIndex; var selText = document.getElementById(fromGroup).options[selItem].text; var selValue = document.getElementById(fromGroup).options[selItem].value; var i; var newItem = true; for (i = 0; i < listLength; i++) { if (document.getElementById(toGroup).options.text == selText) { newItem = false; break; } } if (newItem) { document.getElementById(toGroup).options[listLength] = new Option(selText, selValue); document.getElementById(fromGroup).options[selItem] = null; }}function saveGroup() { var strValues = ""; var boxLength = document.getElementById('grouplist2').length; var elcount = 0; if (boxLength != 0) { for (i = 0; i < boxLength; i++) { if (elcount == 0) { strValues = document.getElementById('grouplist2').options.value; } else { strValues = strValues + "." + document.getElementById('grouplist2').options.value; } elcount++; } } if (strValues.length == 0) { document.forms['groupsform'].submit(); } else { document.forms['groupsform'].group_users.value = strValues; document.forms['groupsform'].submit(); }}</script><form name="groupsform" method="post" action="groups_index.php" target="main_index" onsubmit="setTimeout('window.close()',1000)"> <div align="center"><select multiple='multiple' size='10' id='group1' name='group1' style='width:150' onchange="addUser('group2','group1');" ><?phpwhile($u = mysql_fetch_array($m_result)) { echo "<option value='" . $u['userid'] . "'>" . ucfirst($u['username']) . "</option>";}?></select><select multiple='multiple' size='10' id='group2' name='group2' style='width:150' onchange="addUser('group1','group2');" ></select><input type="submit" value="submit form" onclick="saveGroup();"/> <input type="submit" value="Close" onclick="window.close();" /></div></form>



update: sorry guys i didnt change the saveGroup() it was refering to the old name grouplist2. I changed it now and its work so far. Well hopefully someone will find this useful.
Edited by sonesay (see edit history)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.