Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Help with getting the value of a dropdown box within a radio
Old 08-16-2011, 02:14 AM Help with getting the value of a dropdown box within a radio
Novice Talker

Posts: 7
Trades: 0
Hi guys, completely new to PHP here and I am stuck somewhere and would appreciate some advice.

I have a couple of radio buttons which has an onclick feature to them. Within each of these radio buttons there are sub-dropdown boxes. What I want to do is when I click on the radio option and then subsequently choose an option from the drop down box, I need the values of the drop down boxes as well within the email that will be sent out. At the moment, all I get is the radio button value passed into my email (probably because that's all I am calling at the moment). I have no idea on how to get the values of the drop down boxes in conjuction with the radio button values.

At the moment all I get within my email is this:

Server Specs : Virtual Machine (if I choose the Virtual Machine radio option)

Attached is a snipet of the code that I am using.

HTML Code:
<label class="description" for="machine">Machine Type </label>
        
        <span>
            <input id="Virtual Machine" name="machine" class="element radio" type="radio" value="Virtual Machine" onclick="showstuff('vmdiv'); hidestuff('physdiv');"/>
            <label class="choice" for="Virtual Machine" >Virtual Machine</label>
        
        <div id="vmdiv" style="display:none">
        <font color="#4C787E">    
        <br>Operating System:<br>
            <select name="Virtual Machine">
            <option value="none">None</option>    
            <option value="Windows Server 2003">Windows Server 2003</option>
            <option value="Windows Server 2008">Windows Server 2008</option>
            </select>
        <br>

        <br>Storage Pool:<br>
            <select name="Virtual Machine">
            <option value="cpenas">CPE NAS (standard data pool)</option>    
            <option value="pool2">pool2</option>
            <option value="pool3">pool3</option>
            </select><br>    
        </font>    
        </div>
        
            <input id="Physical Machine" name="machine" class="element radio" type="radio" value="Physical Machine" onclick="showstuff('physdiv'); hidestuff('vmdiv');"/>
            <label class="choice" for="Physical Machine">Physical Machine</label>
        
        <div id="physdiv" style="display:none">
        <font color="#4C787E">            
        <br><b>Physical Machine</b>
            <input type="text">
            </font>
        </div>
        </span> 
and the php for the email that I am using is

PHP Code:
<?php
//error_reporting (E_ALL ^ E_NOTICE);
$errors '';
$machine '';

if(isset(
$_POST['submit']))
{
$machine $_POST['machine'];
}

if( empty(
$errors))
{
    
$email_subject "New Server Order Form submission\n";
    
$email_body "You have received a NEW SERVER ORDER.\n";
    
$email_body .= "\n Server Specs:" .$machine;
    
$to "abc@somemail.com";      

    
mail($to$email_subject$email_body);

    
header('Location: New form thank you.html');
}

So my basic requirement is to get something like this in my email if I choose Virtual machine and its sub options

Server Specs : Virtual Machine Windows Server 2003 pool2



Thanks for the help. I did a brief search through the site but I did not know what exactly to look for.
rapseez is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 08-16-2011, 04:29 AM Re: Help with getting the value of a dropdown box within a radio
Super Spam Talker

Posts: 879
Name: Paul W
Trades: 0
http://www.tizag.com/phpT/examples/formex.php is a good basic grounding for form processing.

Remove spaces from your field names, by the way.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE


*** New:
Please login or register to view this content. Registration is FREE
PaulW is offline
Reply With Quote
View Public Profile
 
Old 08-16-2011, 09:47 PM Re: Help with getting the value of a dropdown box within a radio
Novice Talker

Posts: 7
Trades: 0
Thanks Paul but that link doesnt really help my query much.
rapseez is offline
Reply With Quote
View Public Profile
 
Old 08-16-2011, 09:58 PM Re: Help with getting the value of a dropdown box within a radio
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
JAMISONTUNES
Posts: 2,918
Name: Keith Marshall
Location: Connecticut
Trades: 0
It appears you have javascript controlling the form data, so its hard to tell what is going on. Looking at your raw html form structure, it appears to be wrong syntax.
__________________

<mgraphic /> - I don't have a solution but I admire the problem.
mgraphic is offline
Reply With Quote
View Public Profile
 
Old 08-16-2011, 11:21 PM Re: Help with getting the value of a dropdown box within a radio
Novice Talker

Posts: 7
Trades: 0
Quote:
Originally Posted by mgraphic View Post
It appears you have javascript controlling the form data, so its hard to tell what is going on. Looking at your raw html form structure, it appears to be wrong syntax.
The only bit of JScripting I am using is for the hidestuff and showstuff which is this

Code:
    function showstuff(divid){
        document.getElementById(divid).style.display="block";
    }

    function hidestuff(divid){
        document.getElementById(divid).style.display="none";
    }
Also I dont know if the syntax is right or wrong but I am am getting it to work except for the drop-down boxes within the radio button feature.
rapseez is offline
Reply With Quote
View Public Profile
 
Old 08-17-2011, 06:04 AM Re: Help with getting the value of a dropdown box within a radio
lizciz's Avatar
Super Spam Talker

Posts: 807
Name: Mattias Nordahl
Location: Sweden
Trades: 0
The error is in the drop down names. First off, they should not have spaces, seconds, both drop downs can't have the same name. Here is a simple example, with all the extras stripped off:

HTML Code:
<input name="machine" type="radio" value="VM" />Virtual Machine
        
Operating System:
<select name="VM_OS">
   <option value="none">None</option>    
   <option value="Windows Server 2003">Windows Server 2003</option>
   <option value="Windows Server 2008">Windows Server 2008</option>
</select>

Storage Pool:
<select name="VM_SP">
   <option value="cpenas">CPE NAS (standard data pool)</option>    
   <option value="pool2">pool2</option>
   <option value="pool3">pool3</option>
</select>


<input name="machine" type="radio" value="PM" />Physical Machine

Operating System:
<select name="PM_OS">
   <option value="none">None</option>    
   <option value="Windows Server 2003">Windows Server 2003</option>
   <option value="Windows Server 2008">Windows Server 2008</option>
</select>

Storage Pool:
<select name="PM_SP">
   <option value="cpenas">CPE NAS (standard data pool)</option>    
   <option value="pool2">pool2</option>
   <option value="pool3">pool3</option>
</select>
And then select them in this manner

PHP Code:
if(isset($_POST['submit'])) {
   
$machine $_POST['machine'];
   if (
$machine == 'VM') {
      
$op $_POST['VM_OS'];
      
$sp $_POST['VM_SP'];
   } elseif (
$machine == 'PM') {
      
$op $_POST['PM_OS'];
      
$sp $_POST['PM_SP'];
   }

Of course you can choose which ever names you want (without spaces), I just used VM, PS, OS and SP because it was less for me to write
__________________
Your answers will only be as good as your question. Formulate it well and give all the necessary information.

Last edited by lizciz; 08-17-2011 at 05:02 PM..
lizciz is offline
Reply With Quote
View Public Profile Visit lizciz's homepage!
 
Old 08-17-2011, 03:26 PM Re: Help with getting the value of a dropdown box within a radio
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
JAMISONTUNES
Posts: 2,918
Name: Keith Marshall
Location: Connecticut
Trades: 0
Lizciz, you might want to edit your post and change VM_OP and PM_OP to VM_OS and PM_OS
__________________

<mgraphic /> - I don't have a solution but I admire the problem.
mgraphic is offline
Reply With Quote
View Public Profile
 
Old 08-17-2011, 05:03 PM Re: Help with getting the value of a dropdown box within a radio
lizciz's Avatar
Super Spam Talker

Posts: 807
Name: Mattias Nordahl
Location: Sweden
Trades: 0
Thanks for noticing Keith, it has been corrected
__________________
Your answers will only be as good as your question. Formulate it well and give all the necessary information.
lizciz is offline
Reply With Quote
View Public Profile Visit lizciz's homepage!
 
Old 08-17-2011, 08:42 PM Re: Help with getting the value of a dropdown box within a radio
Novice Talker

Posts: 7
Trades: 0
Thanks mate, I had something worked out exactly similar. I have another doubt if you dont mind me asking.

Say for example;

HTML Code:
<input id="Physical Machine" name="machine" class="element radio" type="radio" value="Physical_Machine" onclick="showstuff('physdiv');"/>

<label class="choice" for="Physical_Machine">Physical Machine</label>
        
<div id="physdiv" style="display:none">
<br><b>Physical Machine</b>
<input type="text">
</font>
 </div>
I have a radio button called "Physical_Machine", that on click shows a text box where you would manually type the physical machine's name. Now similarly to what you helped out with on top, I would like to get the values that were filled into this text box.

Thanks a lot champ.
rapseez is offline
Reply With Quote
View Public Profile
 
Old 08-18-2011, 07:36 AM Re: Help with getting the value of a dropdown box within a radio
lizciz's Avatar
Super Spam Talker

Posts: 807
Name: Mattias Nordahl
Location: Sweden
Trades: 0
Just use a text field instead.

HTML Code:
<input type="text" name="machine_name" />
And retreive the value in the same manner as before
PHP Code:
$machine_name $_POST['machine_name']; 
__________________
Your answers will only be as good as your question. Formulate it well and give all the necessary information.
lizciz is offline
Reply With Quote
View Public Profile Visit lizciz's homepage!
 
Old 08-18-2011, 07:45 AM Re: Help with getting the value of a dropdown box within a radio
lizciz's Avatar
Super Spam Talker

Posts: 807
Name: Mattias Nordahl
Location: Sweden
Trades: 0
Just to clarify, in case it still isn't clear, all form input fields (text, radio, button, textarea etc.) uses the name attribute to identify themself. And no matter what type of input it is, if you specify a name you can always retreive it's value from the $_POST array using it's name, as in $_POST['field_name'].
__________________
Your answers will only be as good as your question. Formulate it well and give all the necessary information.
lizciz is offline
Reply With Quote
View Public Profile Visit lizciz's homepage!
 
Old 08-18-2011, 09:15 PM Re: Help with getting the value of a dropdown box within a radio
Novice Talker

Posts: 7
Trades: 0
Quote:
Originally Posted by lizciz View Post
Just to clarify, in case it still isn't clear, all form input fields (text, radio, button, textarea etc.) uses the name attribute to identify themself. And no matter what type of input it is, if you specify a name you can always retreive it's value from the $_POST array using it's name, as in $_POST['field_name'].
You my friend are a legend. It was so simple. Thanks a lot.
rapseez is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Help with getting the value of a dropdown box within a radio
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.36439 seconds with 12 queries