Solved

textarea to open in select choices

Posted on 2010-09-06
8
324 Views
Last Modified: 2012-06-22
this code opens a textarea if user selects tue

I want the textarea to open if user selects tue or wed
<!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
Comment
Question by:rgb192
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 22

Expert Comment

by:Om Prakash
ID: 33612790
Try
<!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) {

    var word = switchValue.split(",")

    for(i=0; i < word.length ; i++)

    {

    if(value == word[i])

    {

		document.getElementById(textarea).style.display = "block";

		exit;

		}

	else

		document.getElementById(textarea).style.display = "none";



    }

  }

</script>

</head>

<body>

<form method="post" action="pb-dropck.php">

    <select name=t1 onchange="chgDisplayTextarea(this.value, 'textareaID', 'Tue,Wed')">

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

Accepted Solution

by:
ploftin earned 250 total points
ID: 33612831
Use this.
<!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) {
	switch(value) {
      case "Tue":
        document.getElementById(textarea).style.display = "block";
        break;
      case "Wed":
        document.getElementById(textarea).style.display = "block";
        break;
      default:
        document.getElementById(textarea).style.display = "none";
    }
  }
</script>
</head>
<body>
<form method="post" action="pb-dropck.php">
    <select name=t1 onchange="chgDisplayTextarea(this.value, 'textareaID')">
        <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 75

Expert Comment

by:Michel Plungjan
ID: 33612838
onchange="document.getElementById('textareaID').style.display=this.selectedIndex<2?'none':'block'"
0
 

Author Comment

by:rgb192
ID: 33613012
om_prakash_p
works
but I get javascript error
'exit' is undefined
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 5

Expert Comment

by:ploftin
ID: 33614363
Try mine. It works, and no JavaScript errors.
0
 
LVL 22

Assisted Solution

by:Om Prakash
Om Prakash earned 250 total points
ID: 33614736
Use break instead of exit.
<!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) {

    var word = switchValue.split(",")

    for(i=0; i < word.length ; i++)

    {

    if(value == word[i])

    {

		document.getElementById(textarea).style.display = "block";

		break;

		}

	else

		document.getElementById(textarea).style.display = "none";



    }

  }

</script>

</head>

<body>

<form method="post" action="pb-dropck.php">

    <select name=t1 onchange="chgDisplayTextarea(this.value, 'textareaID', 'Tue,Wed')">

        <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
 

Author Closing Comment

by:rgb192
ID: 33657622
thanks
0
 
LVL 5

Expert Comment

by:ploftin
ID: 33658511
My pleasure. Thanks for the points.
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

747 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

13 Experts available now in Live!

Get 1:1 Help Now