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
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)

Link to comment
Share on other sites

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&ymail=info@example.com&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]

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.!!!!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.