?
Solved

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

Posted on 2010-08-31
8
Medium Priority
?
393 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
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 

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 2000 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

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

These days socially coordinated efforts have turned into a critical requirement for enterprises.
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo‚Ķ
The viewer will learn how to count occurrences of each item in an array.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

743 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