Zaloguj | Zarejestruj | FAQ
Anonymous

drop down item not retrieved properly

+ Odpowiedz

Posty: 2 Strona 1 z 1


drop down item not retrieved properly

przez rasagna » Wt maja 06, 2014 7:00 am

Hello ...
How to retrieve particular item selected in drop down menu in php code. It is retrieving properly for 8th semester subjects but not other form items. Please Help



HTML CODE

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Email Attachment Without Upload - Excellent Web World</title>
<style>
body{ font-family:Arial, Helvetica, sans-serif; font-size:13px;}
th{ background:#999999; text-align:right; vertical-align:top;}
input{ width:181px;}
</style>
</head>
<body>
<form action="assign_html.php" method="post" name="mainform" enctype="multipart/form-data">
<table width="500" border="0" cellpadding="5" cellspacing="5">
<tr>
<th>Your Name</th>
<td><input name="fieldFormName" type="text"></td>
</tr>
<tr>
<th>Your USN</th>
<td><input name="fieldFormUSN" type="text"></td>
</tr>
<tr>
<th>Your Email</th>
<td><input name="fieldFromEmail" type="text"></td>
</tr>
<tr>
<th>You Semester</th>
<td>
<select id="opts" onchange="showForm()">
<option value="0">Select Semester...</option>
<option value="1">8 Sem</option>
<option value="2">7 Sem</option>
<option value="3">6 Sem</option>
<option value="4">5 Sem</option>
<option value="5">4 Sem</option>
<option value="6">3 Sem</option>

</select>

<div id="f1" style="display:none">
<form name="form1">
<select id="opts" name="subs" onchange="showForm()">
<option value="0">Select Subject...</option>
<option value="SMS">SMS</option>
<option value="ST">ST</option>
<option value="SA">SA</option>
<option value="INS">INS</option>

</select>
</form>
</div>

<div id="f2" style="display:none">
<form name="form2">
<select id="opts" name="subs" onchange="showForm()">
<option value="0">Select Subject...</option>
<option value="OOMD">OOMD</option>
<option value="WP">WP</option>
<option value="ACA">ACA</option>
<option value="JAVA">JAVA</option>
<option value="C#">C#</option>
<option value="ECS">ECS</option>
</select>
</form>
</div>

<div id="f3" style="display:none">
<form name="form3">
<select id="opts" name="subs" onchange="showForm()">
<option value="0">Select Subject...</option>
<option value="OR">OR</option>
<option value="USP">Unix System Programming</option>
<option value="CG">CG</option>
<option value="ME">ME</option>
<option value="CD">CD</option>
<option value="CN II">CN II</option>
</select>
</form>
</div>

<div id="f4" style="display:none">
<form name="form4">
<select id="opts" name="subs" onchange="showForm()">
<option value="0">Select Subject...</option>
<option value="SE">SE</option>
<option value="SS">SS</option>
<option value="OS">OS</option>
<option value="DBMS">DBMS</option>
<option value="CN I">CN I</option>
<option value="FLAT">FLAT</option>
</select>
</form>
</div>


<div id="f5" style="display:none">
<form name="form5">
<select id="opts" name="subs" onchange="showForm()">
<option value="0">Select Subject...</option>
<option value="MATH 4">MATH 4</option>
<option value="GT">GT</option>
<option value="ADA">ADA</option>
<option value="UNIX">UNIX</option>
<option value="MP">MP</option>
<option value="CO">CO</option>
</select>
</form>
</div>

<div id="f6" style="display:none">
<form name="form6">
<select id="opts" name="subs" onchange="showForm()">
<option value="0">Select Subject...</option>
<option value="MATH 3">MATH 3</option>
<option value="EC">EC</option>
<option value="LD">LD</option>
<option value="DMS">DMS</option>
<option value="DSC">DSC</option>
<option value="OOPS">OOPS</option>
</select>
</form>
</div>

<script type="text/javascript">
function showForm() {
var selopt = document.getElementById("opts").value;
if (selopt == 1) {
document.getElementById("f1").style.display = "block";
document.getElementById("f2").style.display = "none";
document.getElementById("f3").style.display = "none";
document.getElementById("f4").style.display = "none";
document.getElementById("f5").style.display = "none";
document.getElementById("f6").style.display = "none";
}
if (selopt == 2) {
document.getElementById("f2").style.display = "block";
document.getElementById("f1").style.display = "none";
document.getElementById("f3").style.display = "none";
document.getElementById("f4").style.display = "none";
document.getElementById("f5").style.display = "none";
document.getElementById("f6").style.display = "none";
}
if (selopt == 3) {
document.getElementById("f3").style.display = "block";
document.getElementById("f1").style.display = "none";
document.getElementById("f2").style.display = "none";
document.getElementById("f4").style.display = "none";
document.getElementById("f5").style.display = "none";
document.getElementById("f6").style.display = "none";
}
if (selopt == 4) {
document.getElementById("f4").style.display = "block";
document.getElementById("f1").style.display = "none";
document.getElementById("f2").style.display = "none";
document.getElementById("f3").style.display = "none";
document.getElementById("f5").style.display = "none";
document.getElementById("f6").style.display = "none";
}
if (selopt == 5) {
document.getElementById("f5").style.display = "block";
document.getElementById("f1").style.display = "none";
document.getElementById("f2").style.display = "none";
document.getElementById("f3").style.display = "none";
document.getElementById("f4").style.display = "none";
document.getElementById("f6").style.display = "none";
}
if (selopt == 6) {
document.getElementById("f6").style.display = "block";
document.getElementById("f1").style.display = "none";
document.getElementById("f2").style.display = "none";
document.getElementById("f3").style.display = "none";
document.getElementById("f4").style.display = "none";
document.getElementById("f5").style.display = "none";
}
}
</script>
</td>
</tr>

<tr>
<th>Comments</th>
<td><textarea name="fieldDescription" cols="20" rows="4" id="fieldDescription"></textarea></td>
</tr>
<tr>
<th>Attach Your File</th>
<td><input name="attachment" type="file"></td>
</tr>
<tr>
<td colspan="2" style="text-align:center;"><input type="submit" name="Submit" value="Send"><input type="reset" name="Reset" value="Reset"></td>
</tr>
</table>
</form>
</body>
</html>



PHP Code

<?php
$subs = $_POST["subs"];
$fromEmail = $_POST['fieldFromEmail'];
$fromName = $_POST['fieldFormName'];
$usn=$_POST['fieldFormUSN'];
$mes = $_POST['fieldDescription'];
$message = "Name: $fromName\n"
."Email: $fromEmail\n"
."USN: $usn\n"
."Subject: $subs\n"
."Message: $mes\n";

$pfw_subject = "Assignment";
/* GET File Variables */
$tmpName = $_FILES['attachment']['tmp_name'];
$fileType = $_FILES['attachment']['type'];
$fileName = $_FILES['attachment']['name'];

/* Start of headers */
$headers = "From: $fromName";

if (file($tmpName)) {
/* Reading file ('rb' = read binary) */
$file = fopen($tmpName,'rb');
$data = fread($file,filesize($tmpName));
fclose($file);

/* a boundary string */
$randomVal = md5(time());
$mimeBoundary = "==Multipart_Boundary_x{$randomVal}x";

/* Header for File Attachment */
$headers .= "\nMIME-Version: 1.0\n";
$headers .= "Content-Type: multipart/mixed;\n" ;
$headers .= " boundary=\"{$mimeBoundary}\"";

/* Multipart Boundary above message */
$message = "This is a multi-part message in MIME format.\n\n" .
"--{$mimeBoundary}\n" .
"Content-Type: text/plain; charset=\"iso-8859-1\"\n" .
"Content-Transfer-Encoding: 7bit\n\n" .
$message . "\n\n";

/* Encoding file data */
$data = chunk_split(base64_encode($data));

/* Adding attchment-file to message*/
$message .= "--{$mimeBoundary}\n" .
"Content-Type: {$fileType};\n" .
" name=\"{$fileName}\"\n" .
"Content-Transfer-Encoding: base64\n\n" .
$data . "\n\n" .
"--{$mimeBoundary}--\n";
}
if($subs=="OR")
{
$to="operationsresearch@*******";
}
else
{
$to="*****.website@gmail.com";
}
$flgchk = mail ("$to", "$pfw_subject", "$message", "$headers");
// $flgchk=@mail("$to", "$pfw_subject" ,"$pfw_message" ,"$headers" ) ;
if($flgchk){
echo "A email has been sent to: $to";
}
else{
echo "Error in Email sending";
}
?>
Avatar użytkownika

rasagna

  • Posty: 1
  • Dołączył(a): Wt maja 06, 2014 6:53 am

Re: drop down item not retrieved properly

przez XainPro » Śr maja 07, 2014 9:04 am

Your HTMl code is not correct way to do this Replace your code with mine and all the things would work as expected ;0

Kod: Zaznacz cały
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Email Attachment Without Upload - Excellent Web World</title>
<style>
body {
   font-family: Arial, Helvetica, sans-serif;
   font-size: 13px;
}
th {
   background: #999999;
   text-align: right;
   vertical-align: top;
}
input {
   width: 181px;
}
</style>
</head>
<body>
<form action="" method="post" name="mainform" enctype="multipart/form-data">
  <table width="500" border="0" cellpadding="5" cellspacing="5">
  <tr>
    <th>Your Name</th>
    <td><input name="fieldFormName" type="text"></td>
  </tr>
  <tr>
    <th>Your USN</th>
    <td><input name="fieldFormUSN" type="text"></td>
  </tr>
  <tr>
    <th>Your Email</th>
    <td><input name="fieldFromEmail" type="text"></td>
  </tr>
  <tr>
    <th>You Semester</th>
    <td><select id="opts" name="opts" onChange="showForm()">
        <option value="0">Select Semester...</option>
        <option value="1">8 Sem</option>
        <option value="2">7 Sem</option>
        <option value="3">6 Sem</option>
        <option value="4">5 Sem</option>
        <option value="5">4 Sem</option>
        <option value="6">3 Sem</option>
      </select>
      <div id="f1"> </div>
<script type="text/javascript">
function showForm() {
var selopt = document.getElementById("opts").value;
if (selopt == 1) {
document.getElementById("f1").innerHTML = '<select id="opts" name="subs"><option value="0">Select Subject...</option><option value="SMS">SMS</option><option value="ST">ST</option><option value="SA">SA</option><option value="INS">INS</option></select>';
}
else if (selopt == 2) {
document.getElementById("f1").innerHTML = '<select id="opts" name="subs"><option value="0">Select Subject...</option><option value="OOMD">OOMD</option><option value="WP">WP</option><option value="ACA">ACA</option><option value="JAVA">JAVA</option><option value="C#">C#</option><option value="ECS">ECS</option></select>';
}
else if (selopt == 3) {
document.getElementById("f1").innerHTML = '<select id="opts" name="subs"><option value="0">Select Subject...</option><option value="OR">OR</option><option value="USP">Unix System Programming</option><option value="CG">CG</option><option value="ME">ME</option><option value="CD">CD</option><option value="CN II">CN II</option></select>';
}
else if (selopt == 4) {
document.getElementById("f1").innerHTML = '<select id="opts" name="subs"><option value="0">Select Subject...</option><option value="SE">SE</option><option value="SS">SS</option><option value="OS">OS</option><option value="DBMS">DBMS</option><option value="CN I">CN I</option><option value="FLAT">FLAT</option></select>';
}
else if (selopt == 5) {
document.getElementById("f1").innerHTML = '<select id="opts" name="subs"><option value="0">Select Subject...</option>      <option value="MATH 4">MATH 4</option><option value="GT">GT</option><option value="ADA">ADA</option>      <option value="UNIX">UNIX</option><option value="MP">MP</option><option value="CO">CO</option></select>';
}
else if (selopt == 6) {
document.getElementById("f1").innerHTML = '<select id="opts" name="subs"><option value="0">Select Subject...</option><option value="MATH 3">MATH 3</option><option value="EC">EC</option><option value="LD">LD</option><option value="DMS">DMS</option><option value="DSC">DSC</option><option value="OOPS">OOPS</option></select>';
}
else {
document.getElementById("f1").innerHTML = '';
}
}
</script>
</td>
</tr>
<tr>
  <th>Comments</th>
  <td><textarea name="fieldDescription" cols="20" rows="4" id="fieldDescription"></textarea></td>
</tr>
<tr>
  <th>Attach Your File</th>
  <td><input name="attachment" type="file"></td>
</tr>
<tr>
  <td colspan="2" style="text-align:center;"><input type="submit" name="Submit" value="Send">
    <input type="reset" name="Reset" value="Reset"></td>
</tr>
</table>
</form>
</body>
</html>


Good Luck
Avatar użytkownika

XainPro

  • Posty: 3933
  • Dołączył(a): Pt lut 17, 2012 8:10 pm


+ Odpowiedz

Strona 1 z 1

cron