Having trouble with these step. 3. In your script, retrieve the value that the u
ID: 3759620 • Letter: H
Question
Having trouble with these step.
3. In your script, retrieve the value that the user selected from the select box, and store that value (i.e. the 'frog' or the ‘chef’) in a variable.
4. If they selected Kermit, output “It’s not easy being green”. If they selected Swedish Chef output Bork bork bork! (Incidentally, if you'd like to choose other stars or really anything else, be my guest… Just be sure and demonstrate that you recognize that there is a difference in the text between the 'option' tags, and the value containsed inside the 'option' tags).
5. You must use a single 'if/else' for this. That is, do not use two separate 'if' blocks.
6. Demonstrate use of an external stylesheet in this document. You do not have to have any elaborate styling in this page, but apply at least one or two simple styles just so that you can demonstrate use of an external stylesheet.
Explanation / Answer
Since its not mentioned which scripting language to be used, so I will use PHP as scripting language.
1. First of all lets create a form which contains the select box (Combo box) and to design the styling for the form lets create a saperate stylesheet and name that as style.css
File 1: style.css (save this file as style.css )
/* In this file we will define some styling for the select box. */
.selectbox{
text-align: left;
height: 40px;
line-height: 43px;
border-radius: 2px;
border: 1px solid #E2E2E2;
background: transparent url("textfield.jpg") repeat-x scroll left top;
color: #000;
font-size: 13px;
font-family: "Trebuchet MS",Arial,Helvetica,sans-serif;
}
2. Next create HTML file which will contain the form that will be submitted and lets name that file as form.html
File 2: form.html (Save this file in the same folder containing stule.css file)
<html>
<head>
<title>
This is demo for select box
</title>
<!-- Include the external stylesheet style.css ->
<link href="style.css" rel="stylesheet" media="screen">
</head>
<body>
This form will be procesed by processForm.php file
<form method='post' action='processForm.php'>
<select name='select_name' class='checkbox'> <!-- To apply the styling defined in style.css, give same class name to this element ->
<option name='' value='frog'>Kermit</option>
<option name='' value='chef'>Swedish Chef</option>
</select>
<input type='submit' name='submit' value="Submit Form"/>
</form>
</body>
</html>
3. Next part is to process the form by some scripting language and in this case its php and the name of the php file is processForm.php
File 3 processForm.php (Save this file in the same folder)
<?php
// Since the form has been submitted using post method in form.html, so we will have to retrieve the values from the POST array as
$selected_val= $_POST['select_name'];
// Name of the selectbox whose value we have to retrieve.Now selected_val variable contains the selected value
if($selected_val=='frog')
echo "It’s not easy being green";
else
echo "Bork bork bork! ";
</php>
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.