Solved

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

Posted on 2010-08-31
8
385 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
the post value for select box is $_POST['t1']

but what is it for the text area
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
Comment Utility
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
Comment Utility
thanks
0
 

Author Comment

by:rgb192
Comment Utility
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
Comment Utility
You're welcome! Thanks for the points!
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Introduction If you're like most people, you have occasionally made a typographical error when you're entering information into an online form.  And to your consternation, the browser remembers the error, and offers to autocomplete your future entr…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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 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 …

744 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

19 Experts available now in Live!

Get 1:1 Help Now