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
Solved

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

Posted on 2010-08-31
8
389 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
  • 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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
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.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

791 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