Dropdown box, how do I get the selected option?
Moderator: General Moderators
-
Mythic Fr0st
- Forum Contributor
- Posts: 137
- Joined: Sat Dec 02, 2006 3:23 am
- Contact:
Dropdown box, how do I get the selected option?
How do I set
$_SESSION['currmonster']=(theselected option of my dropdown box)
if only I knew what to call it I could figure it out
Any help please & thanks
$_SESSION['currmonster']=(theselected option of my dropdown box)
if only I knew what to call it I could figure it out
Any help please & thanks
- neel_basu
- Forum Contributor
- Posts: 454
- Joined: Wed Dec 06, 2006 9:33 am
- Location: Picnic Garden, Kolkata, India
Method #1 ( If Only 1 option Would be Selected )
===================================
Method #2 ( If multiple options Would be Selected )
====================================
Method #3 (Use A hidden Field To Store To Store The Value Of The Drop Down Box)
==========================================================
Store The Selected Value In A Hidden Field
And Then Track The Value Of That Hidden Field By php
===================================
Code: Select all
$_SESSION['currmonster']=$_POST['select_field_name'];====================================
Code: Select all
<select size="2" name="select_field_name[]" multiple>
<option value="val1">val1</option>
<option value="val2">val2</option>
</select>
Code: Select all
if(!empty($_POST['select_field_name']))
{
foreach($_POST['select_field_name'] as $val)
{
$_SESSION['currmonster'][] = $val;
}
}==========================================================
Code: Select all
<input type="hidden" id="hid_select" value="" name="hid_val">
Code: Select all
<form name="form_name">
<select size="1" name="select_field_name" onclick="pass_val()">
<option value="val1">val1</option>
<option value="val2">val2</option>
</select>
</form>
Code: Select all
function pass_val()
{
var hld_slct = document.form_name.select_field_name;
var get_slct = hld_slct.options[hld_slct.selectedIndex].value;
var hld_trgt = document.getElementById("hid_select");
hld_trgt.value = get_slct;
}Code: Select all
$_SESSION['currmonster']=$_POST['hid_val'];-
Mythic Fr0st
- Forum Contributor
- Posts: 137
- Joined: Sat Dec 02, 2006 3:23 am
- Contact:
ty
Thanks, I basically did the same thing except
$_SESSION['currmonster']=$_POST['name']
works, why the hidden field
$_SESSION['currmonster']=$_POST['name']
works, why the hidden field
-
Mythic Fr0st
- Forum Contributor
- Posts: 137
- Joined: Sat Dec 02, 2006 3:23 am
- Contact:
tried the last one
I tried the last one, it didnt work -.-
Didnt get a value at all o well thanks for trying
Didnt get a value at all o well thanks for trying
- neel_basu
- Forum Contributor
- Posts: 454
- Joined: Wed Dec 06, 2006 9:33 am
- Location: Picnic Garden, Kolkata, India
You Have To Insert
Into The Form Named from_name
===============================
And It Would Look Like This
===============================
And Put Leave The JavaScript As It is In The <head></head>
===============================
I Thought You Put The Hidden Field Out Of The Form
======================================
Code: Select all
<input type="hidden" id="hid_select" value="" name="hid_val">===============================
And It Would Look Like This
===============================
Code: Select all
<body>
<form name="form_name" method="get" action="some_file.php">
<select size="1" name="select_field_name" onclick="pass_val()">
<option value="val1">val1</option>
<option value="val2">val2</option>
</select>
<input type="hidden" id="hid_select" value="" name="hid_val">
<input type="submit" value="Submit" name="Submit">
</form>
</body>===============================
I Thought You Put The Hidden Field Out Of The Form
======================================
-
Mythic Fr0st
- Forum Contributor
- Posts: 137
- Joined: Sat Dec 02, 2006 3:23 am
- Contact:
nop
Nope, didnt work, my code is confusing o_O XD
- neel_basu
- Forum Contributor
- Posts: 454
- Joined: Wed Dec 06, 2006 9:33 am
- Location: Picnic Garden, Kolkata, India
Code: Select all
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>New Page 1</title>
<script>
function pass_val()
{
var hld_slct = document.form_name.select_field_name;
var get_slct = hld_slct.options[hld_slct.selectedIndex].value;
var hld_trgt = document.getElementById("hid_select");
hld_trgt.value = get_slct;
}
</script>
</head>
<body>
<form name="form_name" method=get action="http://localhost/some_file.php">
<select size="1" name="select_field_name" onclick="pass_val()">
<option value="val1">val1</option>
<option value="val2">val2</option>
</select>
<input type="text" id="hid_select" value="" name="hid_val">
<input type="submit" value="Submit" name="Submit">
</form>
</body>
</html>
Code: Select all
$_SESSION['currmonster']=$_POST['hid_val'];-
Mythic Fr0st
- Forum Contributor
- Posts: 137
- Joined: Sat Dec 02, 2006 3:23 am
- Contact:
lol
Yea I know, I named them all right... just didnt work -.-, thanks anyway