473,387 Members | 1,569 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

How to retrieve the text of a drop down list after a POST?


Hello guys,

<SELECT name = "f_hello">
<OPTION value = 'H'>Hello</OPTION>"
<OPTION value = 'G'>Good-Bye</OPTION>"
</SELECT>

In the case above, I can easily retrieve the f_hello variable which will
containts H or G after a POST. But how could I retrieve the "Hello" or
"Good-Bye" string?

Thank you,
Denis
Mar 25 '06 #1
11 1716

Zorro wrote:
Hello guys,

<SELECT name = "f_hello">
<OPTION value = 'H'>Hello</OPTION>"
<OPTION value = 'G'>Good-Bye</OPTION>"
</SELECT>

In the case above, I can easily retrieve the f_hello variable which will
containts H or G after a POST. But how could I retrieve the "Hello" or
"Good-Bye" string?

Thank you,
Denis


You can't automatically. You have to either pass the string itself as
the value or use a lookup on the php processing page. For example:

<SELECT name = "f_hello">
<OPTION value = 'Hello'>Hello</OPTION>"
<OPTION value = 'Good-Bye'>Good-Bye</OPTION>"
</SELECT>

Or alternatively you can leave the HTML the way you had it and do
something like this:

$myvar = ($_POST['f_hello']=='G')?'Good-Bye':'Hello';

The above code simply looks to see if the returned value was a "G", and
if so returns "Good-Bye". Otherwise it returns "Hello". If you have
many values (more than two) you can use a switch case structure like
so:

switch ($_POST['f_hello']) {
case 'G': $myvar='Good-Bye';break;
case 'H': $myvar='Hello';break;
case 'P': $myvar='Please';break;
case 'T': $myvar='Thank You';break;
}

The best option however is to put the correct value in the value clause
in the HTML to begin with as per example 1 above. HTML does not limit
the string supplied in the value clause to only one character. Almost
any text can be present here with a few exceptions regarding special
symbols.

-Robert

Mar 25 '06 #2
Message-ID: <11*********************@i40g2000cwc.googlegroups. com> from
rlee0001 contained the following:
The best option however is to put the correct value in the value clause
in the HTML to begin with as per example 1 above. HTML does not limit
the string supplied in the value clause to only one character. Almost
any text can be present here with a few exceptions regarding special
symbols.


I'd just leave it out... :-)

--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Mar 25 '06 #3
Thanks Robert,

My problem is the drop down list is dynamically filled with a sql query so
I'd have to look up the string from the DB.
Yes, I could pass the string in the value attribute like "H:Hello" also.

I think I'll keep up with the query anyway.

Thanks for helping.
Cheers,
Denis
"rlee0001" <ro*********@hotmail.com> a écrit dans le message de news:
11*********************@i40g2000cwc.googlegroups.c om...

Zorro wrote:
Hello guys,

<SELECT name = "f_hello">
<OPTION value = 'H'>Hello</OPTION>"
<OPTION value = 'G'>Good-Bye</OPTION>"
</SELECT>

In the case above, I can easily retrieve the f_hello variable which will
containts H or G after a POST. But how could I retrieve the "Hello" or
"Good-Bye" string?

Thank you,
Denis


You can't automatically. You have to either pass the string itself as
the value or use a lookup on the php processing page. For example:

<SELECT name = "f_hello">
<OPTION value = 'Hello'>Hello</OPTION>"
<OPTION value = 'Good-Bye'>Good-Bye</OPTION>"
</SELECT>

Or alternatively you can leave the HTML the way you had it and do
something like this:

$myvar = ($_POST['f_hello']=='G')?'Good-Bye':'Hello';

The above code simply looks to see if the returned value was a "G", and
if so returns "Good-Bye". Otherwise it returns "Hello". If you have
many values (more than two) you can use a switch case structure like
so:

switch ($_POST['f_hello']) {
case 'G': $myvar='Good-Bye';break;
case 'H': $myvar='Hello';break;
case 'P': $myvar='Please';break;
case 'T': $myvar='Thank You';break;
}

The best option however is to put the correct value in the value clause
in the HTML to begin with as per example 1 above. HTML does not limit
the string supplied in the value clause to only one character. Almost
any text can be present here with a few exceptions regarding special
symbols.

-Robert

Mar 25 '06 #4
Let me make sure I understand the problem correctly.

Your table in your database looks like this?:

COL1 COL2
H Hello
G Good-Bye

And you are using Col1 (H or G) as a key into the table and you want to
know how to read the other columns from the table when the form is
submitted? Is that correct?

-Robert

Mar 25 '06 #5
True. That would have been most elegant. :o)

-Robert

Mar 25 '06 #6
Yes, you are correct. After the post, I know the value (ex : H ) and I need
the text also. Then I do a SELECT col2 FROM myTable WHERE COL1 = 'H'

I wanted to avoid doing this query by passing both the value and the text
through the post.

Denis

"rlee0001" <ro*********@hotmail.com> a écrit dans le message de news:
11**********************@g10g2000cwb.googlegroups. com...
Let me make sure I understand the problem correctly.

Your table in your database looks like this?:

COL1 COL2
H Hello
G Good-Bye

And you are using Col1 (H or G) as a key into the table and you want to
know how to read the other columns from the table when the form is
submitted? Is that correct?

-Robert

Mar 26 '06 #7
Zorro wrote:
Yes, you are correct. After the post, I know the value (ex : H ) and I need
the text also. Then I do a SELECT col2 FROM myTable WHERE COL1 = 'H'

I wanted to avoid doing this query by passing both the value and the text
through the post.

Denis

"rlee0001" <ro*********@hotmail.com> a écrit dans le message de news:
11**********************@g10g2000cwb.googlegroups. com...
Let me make sure I understand the problem correctly.

Your table in your database looks like this?:

COL1 COL2
H Hello
G Good-Bye

And you are using Col1 (H or G) as a key into the table and you want to
know how to read the other columns from the table when the form is
submitted? Is that correct?

-Robert



<form action="foo.php" method="POST">
<select name="foo">
<option value="G:Good-Bye">G</option>
<option value="H:Hello">H</option>
</select>
</form>

[foo.php]
<?php
if( isset($_POST['foo'] ) {
$values = explode(':', $_POST['foo']);
$col1 = $values[0];
$col2 = $values[1];
}
?>

Is this what you wanted?

-david-
Mar 26 '06 #8
Denis,

David's code with work for the H:Hello syntax you posted before.

But be aware that the user can manipulate both strings so you shouldn't
trust anything you pass via POST. The best way is to do a query on the
destination page. It may seem redundant but it is the least error prone
and compared to parsing apart strings it should be easier to manage as
well if you change things later.

Is client-side JS acceptable? If so put the full string in the
'longvalue' attribute of the option tags. Then on form_onsubmit copy
that attribute's value to a seperate hidden form input element. Use
hiddenfield.value =
getElementById('myselect').getAttribute('longvalue ') or something like
that (untested).

-Robert

Mar 26 '06 #9
Yes, this is a very good solution.

thank you guys for your help;
Denis

"rlee0001" <ro*********@hotmail.com> a écrit dans le message de news:
11**********************@i40g2000cwc.googlegroups. com...
Denis,

David's code with work for the H:Hello syntax you posted before.

But be aware that the user can manipulate both strings so you shouldn't
trust anything you pass via POST. The best way is to do a query on the
destination page. It may seem redundant but it is the least error prone
and compared to parsing apart strings it should be easier to manage as
well if you change things later.

Is client-side JS acceptable? If so put the full string in the
'longvalue' attribute of the option tags. Then on form_onsubmit copy
that attribute's value to a seperate hidden form input element. Use
hiddenfield.value =
getElementById('myselect').getAttribute('longvalue ') or something like
that (untested).

-Robert

Mar 27 '06 #10
what are the true risk of putting an option like this?

<option value="Good-Bye">Good-Bye</option>

what can the user do to mess up this? I don't see the problem...I did a
few <select> where option values are elements of a ENUM so I can't use
the 2 columns coding...is it dangerous? in which way?

Mar 28 '06 #11
Duderino82 wrote:
what are the true risk of putting an option like this?

<option value="Good-Bye">Good-Bye</option>

what can the user do to mess up this? I don't see the problem...I did a
few <select> where option values are elements of a ENUM so I can't use
the 2 columns coding...is it dangerous? in which way?


It's quite easy for me to save the page to my disk, edit it to change the data,
and resubmit it to your site.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Mar 28 '06 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Angie H. | last post by:
Anyone know how to create a drop down menu where the user can enter text also? If they do not want to choose an answer from the drop down menu, the users can just enter their own answers in the...
4
by: Dan | last post by:
Can anyone offer suggestions on how to do this or if it is possible? I have a form that uses a drop down box and 2 text fields. What I am trying to do is have the value of each text box set by...
3
by: Don Wash | last post by:
Hi There! I have a Server-side Drop-down box in ASP.NET (VB) page. What do I do to widen the Drop down box's Pull-Down list's width? I'm not talking about the Drop-down box's width but the box...
3
by: excel_hari | last post by:
Hi, I couldnt locate a Classic ASP group hence posting here. One of my colleagues has designed an intranet site and one of the pages has a drop-down box with close to 300 options. I want to...
1
by: pmelanso | last post by:
Hello, I have a drop down list which is dynatically loaded from a database and I have a second drop down list that is also dynatically loaded depending on what is selected in the first drop down...
2
by: Dave A | last post by:
I am stuggling with databinding a drop down list, hooking into the SelectedIndexChanged and attempting to avoid using the viewstate. The drop down list is quite large so I would prefer to avoid...
8
by: Ed Dror | last post by:
Hi there ASP.NET 2.0 VB & SQL Express Lest take Northwind Categories Products as example I create a table that hold these two together and I create a stored procedure like select ProductID,...
16
by: mj.redfox.mj | last post by:
Can anyone help? I have a textbox which I'm programatically adding by using the following code: txtTest = New TextBox txtTest.ID = "txtLeft" + cntCount.ToString...
3
by: jcassan | last post by:
Hello folks. I am new to these forums and have something, which has been stumping me for little while. I am using pspell to spellcheck a scrolling textbox (textarea) containing user input. I...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.