Jump to content

Recommended Posts

Hi All,

 

I have created a dynamic drop down box where the value is a teams id and the information shown in the box is the teams name.

 

I also need to pass over the teams email address to another page when the submit button is pressed.

 

Is there anyway to do this? Using hidden select fields or something?

 

Thanks in advance

 

Matthew

Link to comment
https://forums.phpfreaks.com/topic/101415-help-me-please/
Share on other sites

You could use a delimiter for the select boxes value, that way you can store the ID and email.

 

Like this:

<option value="ID-Email">Teams Name</option>

 

Then on the next page, you can just use the explode() function to separate the ID and email by the hyphen.

Link to comment
https://forums.phpfreaks.com/topic/101415-help-me-please/#findComment-518701
Share on other sites

The code i am using is:

 

$Query = mysql_query("select * from users WHERE  League = '$League'")
or die(mysql_error());

            <select name="Team_Name">
            <option selected="selected">Team Name</option>
            <?php while ($Row = mysql_fetch_array($Query)){ ?>
		<option value=<?php echo $Row["Team_Name"]; ?>>
		<?php echo $Row["Team_Name"]; ?> </option>
            <?php } ?>   
            </select>

 

pocobueno1388 - how would i go about doing that? I havent done anything like that in the past.

 

Thanks

 

EDIT - I have the teams name passing over now. The information is going to be used inside an email. I need the teams name to be posted over to include in the email but i need the email address to specify where the email is going

Link to comment
https://forums.phpfreaks.com/topic/101415-help-me-please/#findComment-518709
Share on other sites

<?php
print "<form>";
$Query = mysql_query("select Team_Name, teamID from users WHERE League = '$League'")
or die(mysql_error());

while ($Row = mysql_fetch_array($Query)){
$teamName = $Row[0];
$teamID = $Row[1];
$teamDropdown = "<option value=\"$teamID\">$teamName</option>";
}

print "
<select name=\"Team_Name\">
    <option selected=\"selected\">Team Name</option>
$teamDropdown
    </select>
<input type=\"hidden\" name=\"email\" value=\"$email\">
</form>
";
?>

Link to comment
https://forums.phpfreaks.com/topic/101415-help-me-please/#findComment-518736
Share on other sites

Thanks for all the replies. I have tried what was suggested but still no joy.

 

I am trying something like this:

 


	  <select name="Team_Name">
            <?php while ($Row = mysql_fetch_array($Query)){ 
		$Name = $Row["Team_Name"];
		$Email = $Row["email"];?>
		<option value=<?php echo $Name; ?>>
		<?php echo $Name; ?> </option>            
            <?php } ?>            
          </select>    
          <input type="hidden" name="Team1_ID" value="<?php echo $Email; ?>" />

 

This prints out the teams names in the drop down box but does not pass over the value of $Email....as it is out of the loop would this make the value blank?

Link to comment
https://forums.phpfreaks.com/topic/101415-help-me-please/#findComment-518767
Share on other sites

I don't think I understand then. Do you want a form that has a hidden field that changes to the correlating Email address when you select a Team? So you pick a team from the dropdown, you want that team's email address to populate a hidden field? And if you select a different Team, you want that team's address in the hidden email field. Is that it?

 

If so, you'll need to use javascript, unless you want to query the page every time someone selects a different team. And I suspect you'll need to create an array with teamID and Email to populate the hidden field.

 

It would be easier to pass the teamID over to a SQL page, which can fetch the selected team's email address there before updating/deleting.

 

Link to comment
https://forums.phpfreaks.com/topic/101415-help-me-please/#findComment-518779
Share on other sites

Yes, depending on the team selected i would like the hidden email field to be populated by their email address from the query.

 

I cant see why the hidden field cannot be populated by the email address. I have populated hidden fields in the past using while loops.

 

As there is select i dont know how to do it...driving me crazy.

 

There are 2 bits of information that i need passed over to the following page from the select box. Those are the selected teams name and selected teams email address.

 

any ideas anyone?

Link to comment
https://forums.phpfreaks.com/topic/101415-help-me-please/#findComment-518785
Share on other sites

Option 1:

When you select a team from the dropdown, you need to requery. Set javascript to submit form onChange and requery the page based on the selection.

 

Option 2:

Submit the page to a SQL page, which selects the desired team's email address, then do your SQL updates.

 

Option 3:

Use javascript to change the hidden field to the selected team's email address.

Link to comment
https://forums.phpfreaks.com/topic/101415-help-me-please/#findComment-518796
Share on other sites

Fourth option:

 

<?php
$teamName = $_POST['Team_Name'];
list($tName, $tEmail) = split(",", $teamName);
?>

<select name="Team_Name[]">
<?php 
while ($Row = mysql_fetch_array($Query)){ 
$Name = $Row["Team_Name"];
$Email = $Row["email"]; 
print "<option value=\"$Name,$Email\" >$Name</option>";           
?>
</select>    

<?php
print "<p>You selected ClientName: $tName (email: $tEmail)</p>";
?>

Link to comment
https://forums.phpfreaks.com/topic/101415-help-me-please/#findComment-519133
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.