FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


$_Post Variable for Options from Select Types?





NewGuyinTown
Code:


<html>
<head>
    <title>Malden High School</title>
</head>

<body>
<script language="JavaScript">
var school=0;
function addSchool(form){
    form.schools.options[school]=new Option(form.school.value, "s"+school, false, false);
    form.grades.options[school]=new Option(form.from.value+" to "+form.to.value, "g"+school, false, false);
    form.schoolscity.options[school]=new Option(form.city.value, "c"+school, false, false);
    form.schools.size=Math.max(school+1,2);
    form.grades.size=Math.max(school+1,2);
    form.schoolscity.size=Math.max(school+1,2);
    school++;
}
</script>
<center>
<form action="application.php" method="post">
<table>
<tr>
    <td>
    School Name:
    </td>
    <td>
    <input type="text" size="25" name="school">
    </td>
</tr>
<tr>
    <td>
    Grades attend:
    </td>
    <td><select name="from">
    <option value="K">K
    <option value="1">1
    <option value="2">2
    <option value="3">3
    <option value="4">4
    <option value="5">5
    <option value="6">6
    <option value="7">7
    <option value="8">8
    <option value="9">9
    <option value="10">10
    <option value="11">11
    <option value="12">12
    </select> to <select name="to">
    <option value="K">K
    <option value="1">1
    <option value="2">2
    <option value="3">3
    <option value="4">4
    <option value="5">5
    <option value="6">6
    <option value="7">7
    <option value="8">8
    <option value="9">9
    <option value="10">10
    <option value="11">11
    <option value="12">12
    </select>
    </td>
</tr>
<tr>
    <td>
    City:
    </td>
    <td>
    <input type="text" size="25" width="33" name="city">
    </td>
</tr>
<tr>
    <td align="right" colspan="2">
    <input type="button" value="Add School" onclick="addSchool( this.form )">
    </td>
</tr>
</table>

<table width="80%" border="1" rules="none" bordercolor="Black">
<tr>
<td width="40%">
Schools:<br/>
<select type="hidden" name="schools" size="2">
</select>
</td>
<td width="125">
Grades Attended:<br/>
<select type="hidden" name="grades" size="2">
</select>
</td>
<td>
City:<br/>
<select type="hidden" name="schoolscity" size="2">
</select>
</td>
</tr>
<tr>
<td colspan="3" align="right">
<input type="button" value="Remove Selected">
<input type="submit" value="Next Page">
</td>
</tr>
</table>
</center>
</body>
</html>

The Page
Is there a way to get option variables from the previous page without having it selected?
Enderwiggin
I know its possible with php... here's an example:

action.php (The actual script)
Code:
Hi <?php echo $_POST['name']; ?>.
You are <?php echo $_POST['age']; ?> years old


form.php (Has the actual questions and such)
Code:
<form action="action.php" method="post">
 <p>Your name: <input type="text" name="name" /></p>
 <p>Your age: <input type="text" name="age" /></p>
 <p><input type="submit" /></p>
</form>


But i dont know about html, sorry Sad
I got that code from somewhere... cant remember where, they'd probably have better explanations Sad
NewGuyinTown
Sorry for not making this clear... What I wanted to ask if there is a way to get the variables in $_POST[] for the options (not just the selected ones, but the unselected ones as well) of a <select> type.

Code:

<?
session_start();
for( $i=0; !empty($_POST["schools.options[" . $i. "]"]); $i++ ){
     $_SESSION["schools".$i]=$_POST["schools.options[" . $i. "]"];
     echo $_SESSION["schools".$i];
}
for( $i=0; !empty($_POST["schools.s" . $i]); $i++ ){
     $_SESSION["schools".$i]=$_POST["schools.s" . $i];
     echo $_SESSION["schools".$i];
}
echo $_POST["schools"]
?>


Both for statements are false initially. Nothing outputs... I want to get the options from the previous page.
sangharsha
You can use the $_POST['selectFieldName'] for selected value.

If you want to get the unselected values as well, though it sounds some creepy, you need to go a different way.
Create a hidden field to store the values. Call a javascript function before posting the form. Now in the function get all the element values and append it in the hidden field. So finally get the values from the hidden field in the posted page.

If you are finding problems in retrieving unselected values from the select field using the javascript then contact me.

I'll help.
Rhysige
The simplest way would be to make an array of all options and first off use it to display them, secondly send it via a hidden field <input type="hidden" name="hiddenarray" value="' . $array . '" />
Related topics
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.