Solved

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

Posted on 2010-08-31
8
386 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
 

Author Comment

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

but what is it for the text area
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

862 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now