Jump to content

Get text value from selected item in drop down list


Bicklo

Recommended Posts

I am trying to get the tex value of the selected item in a drop down list but nothing seem to work.

 

This is what I got so far.

 

Can anyone guide me in the right direction? Thank you.

<div class="water">


<form action="mail_handler.php" method="post">   

<div class="mailtop">


 


<div class="mailvan"><h1 class="hmailvan">Van:</h1></div>

<div class="mailvanform">
    
<select name="owner" id="owner">
<?php
$sql = mysql_query( "SELECT email FROM namen");
while ($row = mysql_fetch_array($sql)){
echo "<option value=\"owner1\">" . $row['email'] . "</option>";




}


$owner = $_POST['owner'];

?>
</select>    
    
    
    </div>

</div>



<div class="mailvoor"><div class="mailvoortitel"><h1 class="hmailvan">Aan:</h1></div>

<div class="mailvoorform">

  <?php
if(isset($_POST['lombi'])){
    
$mailvoor = $_POST['lombi'];    
 
}

if(isset($_POST['variable'])){
    
    $mailonderwerp = $_POST['variable'];
    
 
    
    
  $eind1= mysql_query("SELECT e1 FROM items WHERE item='$mailonderwerp'");
 
 while ($row = mysql_fetch_object($eind1)){   
    
    $titel1=$row->e1;
     
     
     };
    
 $mails1= mysql_query("SELECT email FROM namen WHERE titel='$titel1'");   
    
  while ($row = mysql_fetch_object($mails1)){   
    
    echo $row->email.' ; ';
     
     
     };
    
    
    
  $eind2= mysql_query("SELECT e2 FROM items WHERE item='$mailonderwerp'");
 
 while ($row = mysql_fetch_object($eind2)){   
    
    $titel2=$row->e2;
     
     
     };
    
 $mails2= mysql_query("SELECT email FROM namen WHERE titel='$titel2'");   
    
  while ($row = mysql_fetch_object($mails2)){   
    
    echo $row->email.' ; ';
     
     
     };    
    
    
    
    
   }    

     
    
$vtest = mysql_query("SELECT d1, d2, d3 FROM items WHERE item='$mailonderwerp'");
    
    


while ($row = mysql_fetch_array($vtest)){
    $doen1 = $row['d1'];
    $doen2 = $row['d2'];
    $doen3 = $row['d3'];
    

}
    

if ($doen1 !=NULL){   
$xtest = mysql_query("SELECT email FROM namen Where titel ='$doen1''");
    
    


while ($row = mysql_fetch_object($xtest)){
  echo '<p><a href=""><div class="namen">'.$row->email.'</div></a></p>';
    
   

}
}    
    
   



if ($doen2 !=NULL){
    
    
$ytest = mysql_query("SELECT * FROM $doen2");
    
    


while ($row = mysql_fetch_object($ytest)){
  echo '<p><a href=""><div class="namen">'.$row->naam.'</div></a></p>';
    
   
}
}
    
    
   

if ($doen3 !=NULL){
    
    
$ztest = mysql_query("SELECT * FROM $doen3");
    
    


while ($row = mysql_fetch_object($ztest)){
  echo '<p><a href=""><div class="namen">'.$row->naam.'</div></a></p>';
    
   
}

}
    

?>    
    



</div>




</div>

<div class="mailtitel">


<div class="mailtiteltitel"><h1 class="hmailvan">Onderwerp:</h1></div>


<div class="mailtitelform">

  <?php
if(isset($_POST['variable'])){
    echo 'DERI '.$_POST['variable'];
}

?>
</div>


</div>


<div class="mailbericht">

<div class="mailberichttitel"><h1 class="hmailvan">Bericht:</h1></div>
    
    <div class="mailberichttitelform">
    
    
    <textarea class="comment" name="comments">
    
    
    
    
    </textarea>
    
    
    </div>   

</div>


<?php


$owner = $_POST['owner'];          //////  here the problem  //////

$myboxes = $_POST['comments'];

echo $owner;


?>
   

<div class="mailsend">

<div class="poper"><input type="submit" name="submit" value="Submit"></div>


</div>
     

 </form>


       
</div>
 

And then

<?php
if(isset($_POST['submit'])){
    $to = "me@mail.com"; // is replaced with my real email
    $from = $_POST['$owner']; // this is the problem
    $first_name = $_POST['first_name'];
    $last_name = $_POST['last_name'];
    $subject = "DERI";
    $subject2 = "Copy of your form submission";

    $message = $from . " schreef volgend bericht:" . "\n\n" . $_POST['comments'];


    $headers = "From:" . $from;

    mail($to,$subject,$message,$headers);

    echo "Mail werd met succes verstuurd.";

    }
?>

What do I mis or what is wrong.

Link to comment
Share on other sites

My point is: The value you receive after the form has been submitted is determined by the value attribute of the option elements. Your options all have the same value, namely “owner1”, so that's obviously nonsense.

 

You need to put the actual e-mail address into the value attribute. And don't forget to escape it.

 

But PDO and PhpMailer are actually more important than your code problems.

Link to comment
Share on other sites

Thank you for replying,

 

I can get the value with javascript

<script>
var e = document.getElementById("owner");
var strUser = e.options[e.selectedIndex].text;

<?php $abc = "<script>document.write(strUser)</script>"?>


</script> 

I have to find a way now to use $abc with $_POST(), no luck so far..

 

Somebody should have mentioned PDO and PhpMailer when I started this (small)project for a friend who is chairman of an association, I wiil have serious look at it before I start something new.

Link to comment
Share on other sites

I can get the value with javascript.

 

No, you cannot. You're grabbing the label, which is something entirely different. I've already explained that to you.

 

 

 

I have to find a way now to use $abc with $_POST(), no luck so far..

 

I've just told you how it works in PHP.

 

How difficult can it be to understand that the value attribute stands for the value? It literally says that.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.