Link to home
Create AccountLog in
Avatar of memberfromuk
memberfromuk

asked on

Hidden textbox to appear in form when 'YES' is selected from drop down box

I have a simpe form which saves records from the text boxes into the database.

if its possible, on the drop down box named 'recent_claims' (Any Claims In Past 5 Year), when 'YES' is selected from the drop down menu, a large text box to appear below it to allow the user to give written explanation of up to 1000 characters(so it has to be fairly large??

the data from this text box is intended to be sent to the recent_claims_y field in the risk_address  table.

--Below is a snippet of riskaddressform.php

Than you.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<?php
session_start();
if (isset($_SESSION['username']) == false){
		header("Location:login.php");
		exit();
	}
	require "connect.php";
	
	$query = "select * from customer";
	$customer_ref = $_GET['customer_ref'];
	$result = @mysql_query($query, $connection)
 or die ("Unable to perform query<br>$query".mysql_error());
	echo "customer_ref should appear here..".$customer_ref;
?>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>GSS - Add Risk Address</title>
<meta name="Keywords" content="" />
<meta name="Description" content="" />
<link href="default.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="header">
	<ul id="menu">
		<li><a href="home.php">Home</a></li>
		<li><a href="search_customer.php" accesskey="2" title="">Customers</a></li>
		<li><a href="reports.php" accesskey="3" title="">reports</a></li>
		<li><a href="search_policy.php" accesskey="4" title="">document management</a></li>
		<li><a href="emailform.php" accesskey="5" title="">email</a></li>
	</ul>
	
	<p style="font-family:verdana;font-size:110%;color:white">
<?php echo(date("l dS F Y") . "<br />");?>
</p>
</div>
<div id="content">
	<div id="colOne">
		<div id="logo">
			<h1><a href="#">gss</a></h1>
			<h2>insurance and property services </h2>
		</div>
		<div class="box">
		  <ul class="bottom"><li></li>
			</ul>
		</div>
		<div class="box">
			<h3>&nbsp;</h3>
			<ul class="bottom"><li></li>
			</ul>
		</div>
	</div>
	<div id="colTwo">
		<h2>Joes website</h2>
		<p class="indent">
	    
<h1 align="center">New Risk Address Details </h1>
 
<form action="addriskaddress.php" method="get">
<p>No Name:<br /><input name="risk_address_no_name" type="text"></p>
<p>Address Line 1:<br /><input name="risk_address1" type="text"></p>
<p>Address Line 2<br /><input name="risk_address2" type="text"></p>
<p>Postcode<br /><input name="risk_address_postcode" type="text"></p>
<p>Property Type<br /><input name="property_type" type="text"></p>
 
<p>Year Built<br />
<select name="year_built">
<option selected>-Select-One-</option>
<?php
$year = 1800;
$currentYear = date(Y);
 
while($year <= $currentYear)
{
 echo "<option value=\"".$year."\">".$year."</option>";
 $year++;
}
?>
</select>
 
<p>Occupancy<br />
  <select name="ownership_occupier">
    <option >[Select one]</option>
    <option >Let on AST</option>
    <option >Let to DSS on AST</option>
    <option >Let to Asylum Seekers</option>
    <option >Vacant</option>
  </select>
</p>
<p>Loss of Rent Cover<br /><input name="loss_of_rent_cover" type="text"></p>
<p>Mortgage Provider<br /><input name="mortgage_provider" type="text"></p>
 
<p>British Standard Security<br />
  <select name="british_standard_security">
    <option >Yes</option>
    <option >No</option>
  </select>
 
<p>Any Claims In Past 5 Years?<br />
  <select name="recent_claims">
    <option >Yes</option>
    <option >No</option>
  </select>
 
<input name="customer_ref" type="hidden" value="<?php echo $customer_ref; ?>" />
<input name="Save" type="submit" value="Save & Continue">
</form>
_______________________________________________________________________________________
</p>
<div class="box">
			<h3>&nbsp;</h3>
			<h4>&nbsp;</h4>
			<p class="bottom">&nbsp;</p>
	  </div>
  </div>
</div>
<div id="footer">
	<p>Copyright (c) 2008 Joe Tzouvanni All rights reserved.</p>
</div>
</body>
</html>

Open in new window

SOLUTION
Avatar of Roonaan
Roonaan
Flag of Netherlands image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of memberfromuk
memberfromuk

ASKER

thank you so much. to be brutally honest this area is new to me.. would it be possible to fuse your code with mine to make it work, as i am lost in this area?

Thank you.
J.
SOLUTION
Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
thats great, but is it possible to have the textbox 'hidden', until 'YES' is selected? and have 'NO' as the preset   word please??
SOLUTION
Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
i'm so SORRY, but after making your changes...the field NO is pre selected, which is what i want HOWEVER, when YES is selected, the textbox does not appear(which is what i want to happen...)??

any ideas?
Sorry, Thanks.

this is the current code i have so far...
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<?php
session_start();
if (isset($_SESSION['username']) == false){
		header("Location:login.php");
		exit();
	}
	require "connect.php";
	
	$query = "select * from customer";
	$customer_ref = $_GET['customer_ref'];
	$result = @mysql_query($query, $connection)
 or die ("Unable to perform query<br>$query".mysql_error());
	echo "customer_ref should appear here..".$customer_ref;
?>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>GSS - Add Risk Address</title>
<meta name="Keywords" content="" />
<meta name="Description" content="" />
<link href="default.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
function testClaimExplanation(selBox) {
  if(selBox.options[selBox.selectedIndex].value.match(/yes/i)) {
    document.getElementById('recent_claims_explanation').style.display = "";
  } else {
    document.getElementById('recent_claims_explanation').style.display = "none";
  }
}
</script>
</head>
<body>
<div id="header">
	<ul id="menu">
		<li><a href="home.php">Home</a></li>
		<li><a href="search_customer.php" accesskey="2" title="">Customers</a></li>
		<li><a href="reports.php" accesskey="3" title="">reports</a></li>
		<li><a href="search_policy.php" accesskey="4" title="">document management</a></li>
		<li><a href="emailform.php" accesskey="5" title="">email</a></li>
	</ul>
	
	<p style="font-family:verdana;font-size:110%;color:white">
<?php echo(date("l dS F Y") . "<br />");?>
</p>
</div>
<div id="content">
	<div id="colOne">
		<div id="logo">
			<h1><a href="#">gss</a></h1>
			<h2>insurance and property services </h2>
		</div>
		<div class="box">
		  <ul class="bottom"><li></li>
			</ul>
		</div>
		<div class="box">
			<h3>&nbsp;</h3>
			<ul class="bottom"><li></li>
			</ul>
		</div>
	</div>
	<div id="colTwo">
		<h2>Joes website</h2>
		<p class="indent">
	    
<h1 align="center">New Risk Address Details </h1>
 
<form action="addriskaddress.php" method="get">
<p>No Name:<br /><input name="risk_address_no_name" type="text"></p>
<p>Address Line 1:<br /><input name="risk_address1" type="text"></p>
<p>Address Line 2<br /><input name="risk_address2" type="text"></p>
<p>Postcode<br /><input name="risk_address_postcode" type="text"></p>
<p>Property Type<br /><input name="property_type" type="text"></p>
 
<p>Year Built<br />
<select name="year_built">
<option selected>-Select-One-</option>
<?php
$year = 1800;
$currentYear = date(Y);
 
while($year <= $currentYear)
{
 echo "<option value=\"".$year."\">".$year."</option>";
 $year++;
}
?>
</select>
 
<p>Occupancy<br />
  <select name="ownership_occupier">
    <option >[Select one]</option>
    <option >Let on AST</option>
    <option >Let to DSS on AST</option>
    <option >Let to Asylum Seekers</option>
    <option >Vacant</option>
  </select>
</p>
<p>Loss of Rent Cover<br /><input name="loss_of_rent_cover" type="text"></p>
<p>Mortgage Provider<br /><input name="mortgage_provider" type="text"></p>
 
<p>British Standard Security<br />
  <select name="british_standard_security">
    <option >Yes</option>
    <option >No</option>
  </select>
 
<p>Any Claims In Past 5 Years?<br />
  <select name="recent_claims" onchange="testClaimExplanation(this);">
    <option value="Yes">Yes</option>
    <option value="No" selected="selected">No</option>
	</select>
 
<div id="claims_explanation" style="display:none">
Please write down the details of your recent claims (max 1000 characters):<br />
<textarea name="recent_claims_explanation" rows="10" cols="60"></textarea>
</div>
 
 
<input name="customer_ref" type="hidden" value="<?php echo $customer_ref; ?>" />
<input name="Save" type="submit" value="Save & Continue">
</form>
_______________________________________________________________________________________
</p>
<div class="box">
			<h3>&nbsp;</h3>
			<h4>&nbsp;</h4>
			<p class="bottom">&nbsp;</p>
	  </div>
  </div>
</div>
<div id="footer">
	<p>Copyright (c) 2008 Joe Tzouvanni All rights reserved.</p>
</div>
</body>
</html>

Open in new window

SOLUTION
Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
ASKER CERTIFIED SOLUTION
Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account