Welcome Guest ( Log In | Register )



 
Reply to this topicStart new topic
> Help: $_post Variable For Options From Select Types?
NewGuyinTown
post Feb 15 2006, 08:57 PM
Post #1


Newbie [ Level 2 ]
Group Icon

Group: Members
Posts: 16
Joined: 15-February 06
Member No.: 11,304



I want to know 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.

Objective: Creating an application for my school.
Issue: I am successful in receiving all the variables from the forms except the ones added to the options of a <select> type. Just wanted to know what is the variable to access the options of <select> types.

Here is what I am trying to do with it:

View Page

If the server is down or unable to load file, here is the script:

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>


Thank you,
Simon Tang.
Go to the top of the page
 
+Quote Post
szupie
post Feb 16 2006, 12:56 AM
Post #2


S.P.A.M.S.W.A.T.
Group Icon

Group: Members
Posts: 814
Joined: 22-January 05
From: San Antonio, Texas (No, I'm not dumb. I just moved here...)
Member No.: 2,284



Wouldn't it work just the same way as any other elements? I think you would refer to your variable by using the value of its name parameter, which, in your case, would be "from" and "to" (so you would use $_POST[from] and $_POST[to]). If that doesn't work, can you reply and clarify more about your problem?
Go to the top of the page
 
+Quote Post
NewGuyinTown
post Feb 16 2006, 03:09 AM
Post #3


Newbie [ Level 2 ]
Group Icon

Group: Members
Posts: 16
Joined: 15-February 06
Member No.: 11,304



urgh. darn page cannot be displayed. got to type again. sad.gif

true... but that's not what I wanted

text field 1
select 1
select 2
text field 2
button 1

button 2 ( function add() ):
add text field 1 to select field 1
add select 1 + " to " + select 2 to select field 2
add text field 2 to select field 3

select field 1
select field 2
select field 3

submit:
post method, next page

$_Post["schools"], $_Post["grades"], and $_Post["schoolscity"] give me the selected values only. I want everything that has been added into the select field stored into session variables on the next page.

And yeah... by variables, I meant name parameters.

I have trouble accessing those values.
Go to the top of the page
 
+Quote Post
vujsa
post Feb 16 2006, 06:29 AM
Post #4


Absolute Newbie
Group Icon

Group: Admin
Posts: 888
Joined: 20-February 05
From: Indianapolis, Indiana, USA (Midwest)
Member No.: 2,714
myCENTs:35.43



To quickly answer your qustion, No. There isn't a way to get informationabout the unselected options. You are only sending information to PHP about the selected option in this case, the value assigned to "from" etc...

You can set other variables ("unselected_1", "unselected_2", "unselected_3") to hold the values of the unselected options with JavaScript but it would be pretty involved.

With JavaScript, I would set all of the "hidden" variables with the select options and when an option is selected, I would deselect the matching hidden variable.

Additionally, you can enter all of the options into you php script in an array and then compare those values to the one that was selected.

vujsa
Go to the top of the page
 
+Quote Post
NewGuyinTown
post Feb 18 2006, 10:37 PM
Post #5


Newbie [ Level 2 ]
Group Icon

Group: Members
Posts: 16
Joined: 15-February 06
Member No.: 11,304



Darn...

I also have another problem...

CODE

function addsession( $school, $grade, $city, $i ){
    $_SESSION["school".$i] = $school;
    $_SESSION["grade".$i] = $grade;
    $_SESSION["city".$i] = $city;
    echo $school;
}


1. I cannot run this function directly from a javascript function.
2. I cannot run this function directly from <input type="button" onClick="addsession( blah blah... )">

I made sure that the arguments are right. It didn't even called scho, so I am assuming that the function had not been run at all.
Go to the top of the page
 
+Quote Post
szupie
post Feb 22 2006, 12:02 AM
Post #6


S.P.A.M.S.W.A.T.
Group Icon

Group: Members
Posts: 814
Joined: 22-January 05
From: San Antonio, Texas (No, I'm not dumb. I just moved here...)
Member No.: 2,284



I'm not an expert at PHP, so please forgive me if I sound like an idiot:
What are the .$i's in your $_SESSION[] variables? Is it something like a concatenate sign?

But I know what I'm talking about in the following:
You cannot trigger a PHP function with Javascript. Javascript is a client-side script, while PHP is server-sided, and it parses files before they are even sent to the client (i.e. your computer). You have to submit the form to the PHP file so that it could parse the information you have given it and then send it back to you. You can use the GET or POST method, or even cookies, to do that.
Go to the top of the page
 
+Quote Post
mastercomputers
post Feb 22 2006, 12:12 PM
Post #7


PESTICIDAL MANIAC
Group Icon

Group: Members
Posts: 626
Joined: 1-September 04
From: Auckland, New Zealand
Member No.: 27



You can indirectly call PHP from Javascript, usually you use the GET method for this, in which case, you send the URL of the PHP page, along with some variables and values using GET as the transport. e.g. submit.php?var1=something&var2=another

In which your script checks for these variables, then processes them as needs be.

But you can't directly call PHP from Javascript. It might be possible, if your Javascript is outputted by PHP though, but you'd still need the function being called to be Javascript, yet using PHP inside that function to process it.

Cheers,


MC
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. How To Reset The Server Variable Php_auth_user(9)
  2. Quickly Create Form Variables(5)
  3. Php Any Variable In String.(1)
  4. Unexpected Error(2)
  5. Send Php Variable To Javascript(5)
  6. Unsupported Operand Types In /(2)
  7. Permanent Variable(7)


 



- Lo-Fi Version Time is now: 23rd November 2008 - 05:01 PM