1

I have these lines of code.

<select id="select12" name="package">
    <option value="0.00">(Select a Package)</option>
    <option value="149.00">PACKAGE A</option>
    <option value="223.00">PACKAGE B</option>
    <option value="273.00">PACKAGE C</option>
</select>

I want to get the "Package A/B/C" and its value. For example if the user selects the Package A. The output is Package A - $149.00. How will I do that? This is the code I have so far in achieving that getting the HTML, but it is no luck.

$package = $_POST['package'];

$email_message = "Form details below.\n\n";

    function clean_string($string) {

        $bad = array("content-type","bcc:","to:","cc:","href");

        return str_replace($bad,"",$string);

    }
 $email_message .= "Selected Package: ".clean_string($package)."\n";
Jennifer
  • 1,291
  • 1
  • 11
  • 16

4 Answers4

1

Try this:

$_POST['package'] will give you value (e.g. 149, 223 etc) and add a hidden textbox and assign select text (e.g. Package A etc) by doing: $( "#select12 option:selected" ).text(); and send that data.

See, if that helps.

Gaurav Dave
  • 6,838
  • 9
  • 25
  • 39
0

The most simplest thing that you can do is:

<select id="select12" name="package">
    <option value="0.00">(Select a Package)</option>
    <option value="PACKAGE A - $149.00">PACKAGE A</option>
    <option value="PACKAGE B - $223.00">PACKAGE B</option>
    <option value="PACKAGE C - $273.00">PACKAGE C</option>
</select>

UPDATE:

For integer value you can use:

preg_match('!\d.+!', $package, $matches);
print_r($matches[0]);
Muhammad Bilal
  • 2,106
  • 1
  • 15
  • 24
  • I used the numerical values to add to other parts of the code, so I wouldn't want t do that... – Jennifer Feb 02 '15 at 06:54
  • @Darren because it will return an empty space and a `$` sign with the numerical part. then we will need to trim it. So its better we use `preg_match` – Muhammad Bilal Feb 02 '15 at 07:09
0

How about simply modify your form like this :

<select id="select12" name="package">
    <option value="0.00">(Select a Package)</option>
    <option value="PACKAGE A - $149.00">PACKAGE A</option>
    <option value="PACKAGE B - $223.00">PACKAGE B</option>
    <option value="PACKAGE C - $273.00">PACKAGE C</option>
</select>
yogipriyo
  • 636
  • 8
  • 13
0
<script src="jquery.js" type="text/javascript"></script>
<script>
$(document).ready(function() {
       $('#select12').change(function(){
            var this_val=$(this).val();
            if(this_val!='0.00')
            {
                var this_html=$( "#select12 option:selected" ).text();
                $('#result').html(this_html+' - $'+this_val);
            }
       });
    });
</script>


<select id="select12" name="package">
    <option value="0.00">(Select a Package)</option>
    <option value="149.00">PACKAGE A</option>
    <option value="223.00">PACKAGE B</option>
    <option value="273.00">PACKAGE C</option>
</select>

<div id="result"></div>
TECHNOMAN
  • 361
  • 1
  • 9