Solved

select menu, that 'tue' makes a textarea input box visible

Posted on 2010-08-31
8
390 Views
Last Modified: 2012-05-10
if select 'tue'
show
textarea


can this text area be displayed when textarea is selected
before submit button is pressed
<form method=post action=pb-dropck.php>
<select name=t1>
<option value=Mon $Mon>Mon</option>
<option value=Tue $Tue>Tue</option>
<option value=Wed $Wed>Wed</option>
<option value=Thu $Thu>Thu</option>
<option value=Fri $Fri>Fri</option>
<option value=Sat $Sat>Sat</option>
<option value=Sun $Sun>Sun</option>
</select>
<input type=submit value=Submit>

Open in new window

0
Comment
Question by:rgb192
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
8 Comments
 
LVL 82

Expert Comment

by:leakim971
ID: 33572419
Use : onchange="if(this.value.indexOf('Tue')==0) document.getElementById('textareaID').style.display='block'; else document.getElementById('textareaID').style.display='none';"

test page :


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<form method=post action=pb-dropck.php>
<select name=t1 onchange="if(this.value.indexOf('Tue')==0) document.getElementById('textareaID').style.display='block'; else document.getElementById('textareaID').style.display='none';">
<option value=Mon $Mon>Mon</option>
<option value=Tue $Tue>Tue</option>
<option value=Wed $Wed>Wed</option>
<option value=Thu $Thu>Thu</option>
<option value=Fri $Fri>Fri</option>
<option value=Sat $Sat>Sat</option>
<option value=Sun $Sun>Sun</option>
</select>
<input type=submit value=Submit>
<textarea id="textareaID" cols="20" rows="20" style="display:none"></textarea>
</form>
</body>
</html>

Open in new window

0
 
LVL 82

Expert Comment

by:leakim971
ID: 33572475
If you want to reuse :

      function chgDisplayTextarea(value, textarea, switchValue) {
            document.getElementById(textarea).style.display = (value.indexOf(switchValue)==0)?"block":"none";
      }

value : current value of the selectbox
textarea : id of the textarea to hide or show
switchValue : First characters to validate the displaying of the textarea or not

Example : chgDisplayTextarea(this.value, 'textareaID', 'Tue')

New test page :

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script language="javascript">
	function chgDisplayTextarea(value, textarea, switchValue) {
		document.getElementById(textarea).style.display = (value.indexOf(switchValue)==0)?"block":"none";
	}
</script>
</head>
<body>
<form method="post" action="pb-dropck.php">
    <select name=t1 onchange="chgDisplayTextarea(this.value, 'textareaID', 'Tue')">
        <option value=Mon $Mon>Mon</option>
        <option value=Tue $Tue>Tue</option>
        <option value=Wed $Wed>Wed</option>
        <option value=Thu $Thu>Thu</option>
        <option value=Fri $Fri>Fri</option>
        <option value=Sat $Sat>Sat</option>
        <option value=Sun $Sun>Sun</option>
    </select>
    <input type=submit value=Submit>
    <textarea id="textareaID" cols="20" rows="20" style="display:none"></textarea>
</form>
</body>
</html>

Open in new window

0
 
LVL 82

Expert Comment

by:leakim971
ID: 33572498
to prevent problem with the case : Tue o tue or tuE or tUe
function chgDisplayTextarea(value, textarea, switchValue) {
		document.getElementById(textarea).style.display = (value.toLowerCase().indexOf(switchValue.toLowerCase())==0)?"block":"none";
	}

Open in new window

0
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 

Author Comment

by:rgb192
ID: 33576379
the post value for select box is $_POST['t1']

but what is it for the text area
0
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 33576500
You need to set a name for it, for example ta1 (going to use $_POST["ta1"]), so we replace :

< textarea id="textareaID" cols="20" rows="20" style="display:none" >< /textarea >

By :


<textarea name="ta1" id="textareaID" cols="20" rows="20" style="display:none"></textarea>

Open in new window

0
 

Author Closing Comment

by:rgb192
ID: 33581565
thanks
0
 

Author Comment

by:rgb192
ID: 33581678
i have a similar question

I am trying to put this code in a php function
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/Q_26445679.html
0
 
LVL 82

Expert Comment

by:leakim971
ID: 33582423
You're welcome! Thanks for the points!
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question