Jump to content

Passing variable from dropdown list


ajentp

Recommended Posts

Hi

 

I am trying to make a PHP mail script, where -based on customer feedback- e-mail template can be sent. Emails template are listed in drop down list at the top of the page. Underneath, is a display of customer records. Each record has a button ,if clicked, it will send the e-mail template as selected in the dropdown list.

 

 

 

I am having difficulty to pass parameter form dropdown list to PHP file where that parameter will be used to select the template from the database.

 

Here is the code:

<code>

$qE = sprintf("SELECT * From mail");

$resE = mysql_query($qE);

//$roE = mysql_fetch_array($resE);

$rowcount = mysql_num_rows($resultE);

echo "<select size='1' name='temp'>";

 

for($z=0; $z< $rowcount; $z++)

{

$roE = mysql_fetch_array($resE);

$title = $roE ['name'];

$mid = $roE ['id'];

echo"<option value='$id'>$title</option>";

 

//////////////////////////////////////////////// I would like to pass $id as parameter whose name is temp

}

echo"</select></font><br>";

 

do {

//////////////////////the data below is selected from another table whose query not shown here

$name = $row ['name'];

$ymail = $row ['ymail'];

$fname = $row ['fname'];

$fmail = $row ['fmail'];

$domain= $row ['url'];

$comments = $row ['comments'];

 

?><div style="border:1px solid #800080; position: relative ; width: 715px; z-index: 2; left: 4px; top: 3px; padding: .3em; background-color: #FFCC99" id="layer3">

<p align="center"><b><font face="Tahoma" size="4">Record <?php echo $x; ?> </font></b><p align="left">

<font face="Tahoma" size="2"><b>Name:</b> <?php echo $name; ?></font><br>

<font face="Tahoma" size="2"><b>Email:</b> <?php echo $ymail; ?></font><br>

<font face="Tahoma" size="2"><b>Friend's Name:</b> <?php echo $fname; ?></font><br>

<font face="Tahoma" size="2"><b>Friend's Email:</b> <?php echo $fmail; ?></font><br>

<font face="Tahoma" size="2"><b>Page Forward:</b> <?php echo $url; ?></font><br>

<font face="Tahoma" size="2"><b>Comments:</b> <?php echo $comments; ?></font><br>

<font face="Tahoma" size="2"><b>Email Template:</b>

 

<?php //echo temp;

$temp = $_REQUEST['temp'];

//echo $temp;?>

 

/////////////////////////////////////here is my problem: the very last parameter temp. This is being forwarded as empty.

 

<input type="button" name="submit2" value="Email" onClick="document.location.href='maincheck.php?name=<?php echo $name;?>&ymail=<?php echo $ymail;?>&temp=<?php echo $temp;?>'"/></div>

 

<?php $x++;} while ($row = mysql_fetch_array($result));

?>

</code>

 

Any help is very appreciated.

 

Thanks

 

Link to comment
https://forums.phpfreaks.com/topic/176761-passing-variable-from-dropdown-list/
Share on other sites

1. user code tags [ not < (or use the # button)

2.

$mid = $roE ['id'];
echo"<option value='$id'>$title</option>";

should be

$mid = $roE ['id'];
echo"<option value='$mid'>$title</option>";

3. I assume the code

<?php //echo temp;
$temp = $_REQUEST['temp'];
//echo $temp;?>

is on the page the form posts to (PS i can't see any forms)

Hi,

 

I am basically trying to accomplish this code without <form>.

 

I realized it that $temp = $_REQUEST['temp']; is irrelevant and need to be removed from the code. I misunderstood that this way I can store dropdown list value into $temp to be used later in the URL

 

So basically, what I am unable to do is related to this  part: &temp= <the value of selected dropdown list> at the following code: I am unable to assign any value. When button clicked, the URL  look like this:

 

/maincheck.php?name=First&[email protected]&temp=

 

you can see no value is passed for temp

 

<input type="button" name="submit2" value="Email" onClick="document.location.href='maincheck.php?name=<?php echo $name;?>&ymail=<?php echo $ymail;?>&temp=<?php echo $temp;?>'"/></div> ////Here<-----------

 

any help please [/code]

I'm going to move this to the JavaScript Section,

the reason is because the solution seams to more client based..

 

if you change your onclick to something like (untested)

onclick="javascript:window.location = maincheck.php?name=<?php echo $name;?>&ymail=<?php echo $ymail;?>&temp=getElementByName('temp').options[getElementByName('temp').selectedIndex].value"

 

it maybe easier to write a small JS function get all of the values and then to open the page

Yup!!!! thats drop down lists in browsers,

there are three different formats of <select> effectively and how that is read by three of the 5 major browser clients (chrome,explorer,safari,opera,netscp/mozilla.org's).

 

Unfortunately, the only way past it is to put the <select> and its "options" outside the form element.

Then put a

<input name="supplementcarrier" id="supplementcarrier" type="hidden" value="">

inside the form element and load it by a script that gets the options array and selected index,

then its value and then place it in the hidden field , then send the form.

 

Thats just the cheap and easy way out.!!!!

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.