Congratulations to AcaCandy on her 100,000th post!
There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
 
Tag Cloud
acer black screen blue screen boot bsod computer connection crash css dell driver drivers email error ethernet excel firefox firefox 3 game hard drive internet internet explorer itunes laptop linux malware monitor network networking nvidia outlook outlook 2003 outlook 2007 outlook express partition problem router slow software sound trojan usb video virus vista wifi windows windows vista windows xp wireless
Web Design & Development
Search
Search in:
 
Advanced Search
Tech Support Guy Forums > Internet & Networking > Web Design & Development >
Solved: PHP/HTML variable interrogation help


HELLO AND WELCOME! Before you can post your question, you'll have to register -- it's completely free! Click here to join today! We highly recommend that you print a copy of our Guide for New Members. Enjoy!

Closed Thread
 
Thread Tools
tmjhayward's Avatar
Member with 36 posts.
 
Join Date: Jul 2005
Location: Northeastern US
Experience: Intermediate
25-Jan-2008, 03:31 PM #1
Solved: PHP/HTML variable interrogation help
Hi. I'm totally new to HTML and PHP. I'm creating an online questionnaire where the responses are primarily radio buttons, with a few text fill-in spots. Some are single response only, and some are 'select all that apply.' This works fine. However, I have some questions that have additional responses depending on the initial response. (code below - if user selects 10a, they can't select 10b - that works fine - but I also don't want them to be able to select 10b.1 thru 10b.4, or perhaps the text box also). How do I interrogate the response dynamically (and prior to submitting the form) to do this? I tried $variable = $_POST['name'] within the PHP section as shown below. Or can that only be used if the form's already been submitted? How else would it be done?

Also, once a radio button is selected in a section that allows multiple selections, how do I get it to be unselected if they click on it again?

Here's the part of my code I need help with.
. . .
<li>Overall, how would you rate your level of satisfaction with the industry?</li>
<dt><input type="radio" name="ques10" value="10a" / > I am satisfied. </dt>
<?php
$resp = $_POST['ques10'];
IF $resp == "10a" {here I want to disable ques 10b.1 - 10b.4, and maybe also the text area}; /*also if they uncheck 10a, I need to re-enable the sub-questions for ques 10b */
?>
<dt><input type="radio" name="ques10" value="10b" / > I am dissatisfied. <i> (please select all that apply) </i></dt>
<dd><input type="radio" name="ques10b.1" value="10a" /> interruptions</dd>
<dd><input type="radio" name="ques10b.2" value="10b" /> same-company visits</dd>
<dd><input type="radio" name="ques10b.3" value="10c" /> Quality of discussion </dd>
<dd><input type="radio" name="ques10b.4" value="10d" /> Other <i> (please specify)</i><br />
<textarea name="10_other" rows="4" cols="55"></textarea></dd>
</li>

. . .

Thanks for any help anyone can give me!
MJ
MMJ's Avatar
MMJ MMJ is offline
Distinguished Member with 3,248 posts.
 
Join Date: Oct 2006
26-Jan-2008, 11:51 AM #2
PHP Code:
<?php
$resp 
$_POST['ques10'];
if (
$resp == "10a"):
?>
<dt><input type="radio" name="ques10" value="10b" / > I am dissatisfied. <i> (please select all that apply) </i></dt>
<dd><input type="radio" name="ques10b.1" value="10a" /> interruptions</dd>
<dd><input type="radio" name="ques10b.2" value="10b" /> same-company visits</dd>
<dd><input type="radio" name="ques10b.3" value="10c" /> Quality of discussion </dd>
<dd><input type="radio" name="ques10b.4" value="10d" /> Other <i> (please specify)</i><br />
<textarea name="10_other" rows="4" cols="55"></textarea></dd>
<?php
endif;
?>
</li>
tmjhayward's Avatar
Member with 36 posts.
 
Join Date: Jul 2005
Location: Northeastern US
Experience: Intermediate
26-Jan-2008, 07:03 PM #3
Thanks for the response, MMJ. I've never seen anything about using an 'endif' in PHP, nor using a colon after the if statement, although neither of these gave me an error. However, I didn't get the results I need. What I want is to provide the user with 2 responses -#1 satisfied or #2 not satisfied. The second response has sub responses a, b, c and d, that should only apply IF they select response #2. So if they select response #1, I don't want them to be able to select the sub responses that only pertain to #2. I can limit them to selecting #1 or #2 by naming them the same, but don't know how to prevent them from selecting the sub-responses. Once the user selects #1, I need to know that so that I can disable the sub-responses for #2 before they can select them. Also, vice versa, if they change their mind and select #2 (which automatically un-selects #1) I want to re-enable the sub-responses.

Is this possible? In the following statement:
<input type="radio" name="ques10" value="10a" / > I am satisfied. </dt>
<input type="radio" name="ques10" value="10b" / > I am not satisfied. </dt>
I want to set a variable to equal either 10a or 10b, and then interrogate the variable. The $_POST doesn't seem to work. How do I code it?

My other question was, I have several sections with radio buttons where they can select all that apply. I assumed it would un-select if they clicked on it again, but that's not happening. Do you know how I can do this?


Thanks again for anyone's help.
MJ
jaymanson's Avatar
Computer Specs
Senior Member with 213 posts.
 
Join Date: Mar 2007
Location: Christchurch, New Zealand
Experience: Advanced Design/HTML/CSS - Intermediate PHP
26-Jan-2008, 09:11 PM #4
Hi MJ,

POST is only a method of sending information from one file to another - for example from a form on an HTML page to a PHP processing script - and can only operate when the page has been submitted. To change elements on a web page in real time you need to use Javascript.

In answer to your second question, these should really be checkboxes instead of radio buttons. I've changed them in the example below:

Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script type="text/javascript">
function enable()
{
document.getElementById('10b1').disabled=false;
document.getElementById('10b2').disabled=false;
document.getElementById('10b3').disabled=false;
document.getElementById('10b4').disabled=false;
document.getElementById('10b5').disabled=false;
}
function disable()
{
document.getElementById('10b1').disabled=true;
document.getElementById('10b2').disabled=true;
document.getElementById('10b3').disabled=true;
document.getElementById('10b4').disabled=true;
document.getElementById('10b5').disabled=true;
}
</script>
</head>
<body>
<p>Overall, how would you rate your level of satisfaction with the industry?</p>
<form name='survey' method='post' action="#" >
<dt><input type="radio" name="ques10" value="10a" onclick="javascript: disable()" checked /> I am satisfied. </dt>
<dt><input type="radio" name="ques10" value="10b" onclick="javascript: enable()" /> I am dissatisfied. <i> (please select all that apply) </i></dt>
<dd><input id="10b1" type="checkbox" name="ques10b.1" value="10a" disabled="true" /> interruptions</dd>
<dd><input id="10b2" type="checkbox" name="ques10b.2" value="10b" disabled="true" /> same-company visits</dd>
<dd><input id="10b3" type="checkbox" name="ques10b.3" value="10c" disabled="true" /> Quality of discussion </dd>
<dd><input id="10b4" type="checkbox" name="ques10b.4" value="10d" disabled="true" /> Other <i> (please specify)</i><br />
<textarea id="10b5" name="10_other" rows="4" cols="55" disabled="true" ></textarea></dd>
</form>
</body>
</html>
Hope this helps

Jay
tmjhayward's Avatar
Member with 36 posts.
 
Join Date: Jul 2005
Location: Northeastern US
Experience: Intermediate
26-Jan-2008, 09:30 PM #5
Thanks, Jay. I thought that perhpas $_POST could only be used once the form was submitted. Do I have to use javascript even with checkboxes - if I want the ability to turn them on and off? I'm just getting started with html and php - I'm almost afraid to add another level of complexity right now!

Anyway, thank you so much for the help. I really appreciate it!
MJ
jaymanson's Avatar
Computer Specs
Senior Member with 213 posts.
 
Join Date: Mar 2007
Location: Christchurch, New Zealand
Experience: Advanced Design/HTML/CSS - Intermediate PHP
27-Jan-2008, 12:34 AM #6
Yes, POST variables need to be submitted. Alternatively GET variables can be transferred via something as simple as a link such as http://www.yoursite.com/index.php?name=bob&age=30

Both POST & GET do require either the existing page to be reloaded to use those variables, or a redirection to another page or processing script to have any effect.

If you need to make any alterations to the HTML without reloading or redirecting, such as disabling checkboxes depending on user input, you've got to use Javascript - no way round that I'm afraid.

The next thing you'll need to do is write a PHP script to then process the information given in the form. PHP and Javascript scripting is a little more advanced than HTML, but the best way to learn is just by doing it And you can always pop by here for advice if you get stuck

Jay
MMJ's Avatar
MMJ MMJ is offline
Distinguished Member with 3,248 posts.
 
Join Date: Oct 2006
27-Jan-2008, 03:28 AM #7
tmjhayward's Avatar
Member with 36 posts.
 
Join Date: Jul 2005
Location: Northeastern US
Experience: Intermediate
27-Jan-2008, 10:21 AM #8
Thanks again, Jay. Yes, my next step is to write the php to insert the data in a table. Hopefullly I can just use the javascript example you gave me to handle the little bit Iwhere need to be able to uncheck the boxes.
MJ
Closed Thread

THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
WELCOME TO TECH SUPPORT GUY! Are you looking for the solution to your computer problem? Join our site today to ask your question -- for free! Our site is run completely by volunteers who help people like you solve computer problems. See our Welcome Guide to get started.



Thread Tools


You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 01:14 AM.
Copyright © 1996 - 2008 TechGuy, Inc. All rights reserved.
Powered by vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Powered by Cermak Technologies, Inc.