Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Form Question - Is it possible to have 2 different values? 1

Status
Not open for further replies.

skwurl

Technical User
Sep 30, 2005
87
I have a drop down box that has all of the state/provinces. Depending on what state/province you select, the form emails it to a different address. Everything works fine.

Except...

I need the form to email what state/province the user selected. Since I'm already using the value tag for each state/province to specify what email I want, is it possible to have another value tag so I can also send the name of the state/province?

Sorry if this doesn't make sense. I'll clarify if you're confused.
 
You could add arbitrary properties to the option tag...
Code:
<option value="email@x.y.com" value2="New York State">Someplace</option>
And you would then access those properties in the way you would normally access the value property:
Code:
<select onchange="alert(this.value2);">
You might consider putting both into the same value property:
Code:
<option value="email@x.y.com|New York State">Someplace</option>
They are seperated by a "|" character and you would access them like this:
Code:
<select onchange="alert((this.value).split('|')[0]+'\n\n'+(this.value).split('|')[1]);">
That's the idea anyway [smile]

Let us know how you go!
Jeff

[tt]Jeff's Page [/tt][tt]@[/tt][tt] Code Couch
[/tt]
 
what I would do is have a conditional statement or lookup on the server side, once the form has been submitted. it will determine which email address to send to based on the state/province selected. this would be your safest bet (or parsing a combined string), because javascript is not enabled in all users' browsers.

*cLFlaVA
----------------------------
[tt]your mom goes to college[/tt]
[URL unfurl="true"]http://www.coryarthus.com/[/url]
[banghead]
 
I'm using an external txt file to send the email. An example value would be:

<option value="../cgi-bin/request/email1.txt">Minnesota</option>

The txt file has html embedded in it like so:

To: email1@email.com
From: <>
Subject: Test

(the rest is html message)
 
If you're using server-side code to send the email (and you should be, btw), then just send one value back from the form to the script, and have the script look up the appropriate value for the other and append it to the mail it generates.

-- Chris Hunt
Webmaster & Tragedian
Extra Connections Ltd
 
Sorry, I'm kinda of a newbie to CGI scripting and such...

I'm not sure if I'm using server-side code to send the email. I'm referencing the email from a txt file located in my CGI-BIN directory, is that what you mean?
 
What is in the <form> tag on your page (specifically the contents of the action property)?

This will tell us where the data from the form is being processed - I'm fairly confident in saying it'll be a .cgi script running on the web server you are hosting on... and that it does the emailing server-side (and on a hunch I'll say it's probably a Perl script).

Let's not get ahead of ourselves, though.

Cheers,
Jeff

[tt]Jeff's Page [/tt][tt]@[/tt][tt] Code Couch
[/tt]
 
Hi Jeff,

Yeah, it's a perl script located in the CGI-BIN directory. The name of my dropdown box is called "_send_email1". This tag is unique to the script. I entered the values for the state/provinces to be ../cgi-bin/request/email1.txt, ../cgi-bin/request/email2.txt. or ../cgi-bin/request/email3.txt (depending on which state). All 3 txt files have different emails in them. So far, everything works fine, and the form sends out the different emails per unique state.

However...

Since I already used the value tag to tell what txt file to look at, I can't register what state they chose.

I'm bascially looking for a way to add a second value to an input option.
 
Since I already used the value tag to tell what txt file to look at, I can't register what state they chose.
Why not place a unique US State variable (MN, OR, TX etc) in the input boxes instead of the path to the txt file containing the email?

Then, modify the Perl script located in the CGI-BIN directory so that it takes the value from the input (say, TX) and then sets up some variables that contain not only the email address but any other information specific to that state. Then send off the email(s) using what is left of your script.

This has obvious security benefits as well... since there is no list of txt files referenced client-side for people to start fiddling with.

I understand that you may not be the worlds best Perl developer and that this may seem like a massive undertaking. It's not. You will probably find plenty of people here willing to help you. Having said that, if you decide to take our suggestions and change the "back-end" then you are probably going to be better off asking about specifics in the Perl Forum: forum219 or the CGI Forum: forum452

Cheers,
Jeff

[tt]Jeff's Page [/tt][tt]@[/tt][tt] Code Couch
[/tt]
 
Hidden field on the form that get's set with the state when the user selects from the drop-down list might be a far simpler solution.

Never be afraid to share your dreams with the world.
There's nothing the world loves more than the taste of really sweet dreams.
 
Thanks for the responses Jeff. I'll look into the Perl forums.

Dwafthrower: How would you trigger a hidden field from a drop down selection?
 
skwurl said:
How would you trigger a hidden field from a drop down selection?

Using javascript, write an event handler for the <select> tag's onchange event to set the value of the hidden field.

Never be afraid to share your dreams with the world.
There's nothing the world loves more than the taste of really sweet dreams.
 
I know, but I don't know how to configure my script that way.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top