473,385 Members | 1,752 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

How to show a hidden text-box when a specific option is selected.

ddtpmyra
333 100+
This is just a follow-up question above, this time i wanted to have a dependend drop down that when the users selected 'others' for instance another texbox will show-up right next to my drop down. How can I do it from my code or should I place the condition if ever?

thanks,
DM

Expand|Select|Wrap|Line Numbers
  1. echo '<tr><td><b>Lead Generated By:</b></td>'; 
  2. $res=mysql_query("select lead  from tblgenerated"); 
  3. if(mysql_num_rows($res)==0){ 
  4. echo "there is no data in table.."; 
  5. } else { 
  6.  
  7.     echo '    <td width="100%"><select name="lead" id="lead" value=\"$lead\">'; 
  8.                     for($i=0;$i<mysql_num_rows($res);$i++) { 
  9.                     $row=mysql_fetch_assoc($res); 
  10.                     echo"<option value=\"$row[lead]\" "; 
  11.                     if($lead==$row[lead]) 
  12.                     echo "selected"; 
  13.                     echo ">$row[lead]</option>";     
  14.     } 
  15.     echo "</select><br></tr></td>"; 
  16.     } 
  17.  
  18.  
Feb 11 '09 #1
8 15229
hoopy
88
This sounds like you need something client side, i.e Javascript or AJAX. Add an "on change" event in the select box which checks if the value is "0" or something and if so display a hidden input box next to the drop down using CSS display; ? I dont think it should be something which needs a PHP refresh. Maybe I am misunderstanding your question though.
Feb 11 '09 #2
Atli
5,058 Expert 4TB
Yep, again, hoopy is spot on :)

The *best* way to dynamically change minor details on your page, like enabling elements, is to use JavaScript.
(* Best in like 95% of cases, as not all browsers will have JavaScript enabled)

Simply create a <select> tag, and have the onchange event of that tag enable the box if the value of the selected option is set to a predefined value.

For example, you could put this into the <head></head> tags:
Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2. function ToogleTextbox(pValue) {
  3.   var textBox = document.getElementById('OtherBox');
  4.   if(pValue) {
  5.     textBox.style.display = "block";
  6.   }
  7.   else {
  8.     textBox.style.display = "none";
  9.   }
  10. }
  11. </script>
  12.  
This function would simply find the <input> with the id "OtherBox", and then uses the display style to either show it or hide it.

And then do something like this for your <select> tag:
Expand|Select|Wrap|Line Numbers
  1. <select name="MySelect" onchange="javascript: ToogleTextbox(this.value == 'null');">
  2.   <option value="null">Other</option>
  3. </select>
  4. <input type="text" name="OtherBox" id="OtherBox" style="display: none;" />
  5.  
Which basically tells your <select> element to call the ToogleTextbox function, and send a boolean value, indicating whether the <option> with the value "null" is selected.
Feb 11 '09 #3
xaxis
15
If you want multi-level drop down menus and a high degree of cross browser support, you COULD use nothing but CSS. Using something like:

Expand|Select|Wrap|Line Numbers
  1. div#hiddenMenu {
  2.     position:absolute;
  3.     // positioned where you would like the div with the id 'hiddenMenu' to appear
  4.     visibility:hidden;
  5.     width:200px;
  6.     height:200px;
  7.     border:1px solid #000;
  8. }
  9.  
  10. span#menuItem:hover > #hiddenMenu {
  11.     visibility:visible;
  12. }
I won't go into more detail than that for this is the javascript forum. Just thought I'd add to the many possibilities.
Feb 13 '09 #4
hsriat
1,654 Expert 1GB
Expand|Select|Wrap|Line Numbers
  1.     <select>
  2.         <option onclick="if (this.selected) document.getElementById('others').style.display='block';">others</option>
  3.         <option selected="selected" onclick="if (this.selected) document.getElementById('others').style.display='none';">HHH</option>
  4.     </select>
  5.     <input type="text" style="display:none;" id="others"></input>    
  6.  
Feb 14 '09 #5
ddtpmyra
333 100+
Hello again,

This is just a follow-up question and somewhat similar with same problem I had. This time I have javascript that has option to hide and show the button. But I dont know how to insert the sql query on the event action.

My forms is like this:
Expand|Select|Wrap|Line Numbers
  1. echo'<input id="showbutton" type="button" value="' . translate ( "Show" )
  2.      . '" onclick="showComments();" />';
My javascript is like this:
Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2. function showComments()
  3. {
  4. alert("I want to show the information from mysql how?!");
  5. }
  6. </script>
  7.  
Question:
Where can i put the query select contidtion on javascript event? Please advice.
Sep 8 '09 #6
acoder
16,027 Expert Mod 8TB
Use PHP to get the MySQL data and generate a string. Then use PHP code to generate the JavaScript code.
Sep 9 '09 #7
ddtpmyra
333 100+
@acoder
Hi Acecoder,

can you insert php inside the msgbox or alertbox?
Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript"> 
  2. function showComments() 
  3. alert("I want to show the information from mysql how?!"); 
  4. </script>
im not good in javascript so i need little more help and specific what to do. Or are there option where you can use to show texbox with information instead of the alert box?

thanks!
Sep 10 '09 #8
acoder
16,027 Expert Mod 8TB
@ddtpmyra
Yes, with something like:
Expand|Select|Wrap|Line Numbers
  1. function showComments() 
  2. alert("Information from mysql: <?php echo $str; ?>"); 
assuming it's escaped properly to avoid string problems.

are there option where you can use to show texbox with information instead of the alert box?
Yes, that would actually be better. Use a container element, e.g. div and have it hidden initially (but with the information already generated from PHP), and then in showComments show it using elem.style.display = "block".
Sep 10 '09 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Bonnie | last post by:
Hi: I'm hoping someone can shed some light on this issue. (I've been digging around everywhere and can't seem to find it by searching): I use the @import statement to attach an external style...
1
by: Thomas | last post by:
How can I detect hidden text in a Word document using C#? -Thomas
1
by: Filip De Backer | last post by:
Hi everyone, I have some fields from a database which contain html text. How can I show this text in an asp page (<b> must be bold, red must be red text, ...)? thanks for the answers, Filip
7
by: FP | last post by:
I'm new to Java Script. I'm displaying comments people have made. Below each persons' comment I want to add 2 buttons "Reply" and "Amend". Clicking "Reply" would display an empty text field...
2
by: harvie wang | last post by:
Hi, I want to show vertical text in textbox, how to do? Best Wish, Harvie 2006-7-16
0
by: Kasya | last post by:
How Can i make a hidden text in console application on my cin >> x;
1
by: Tim Kelley | last post by:
Is there a way to have GetFiles() show hidden files also? Thanks
4
by: =?Utf-8?B?UGF1bCBSZWVk?= | last post by:
Greetings. I have an app that's been in production for 3-4 years that is hosted at an ISP. I have an aspx control on the page that uses a few hidden text fields for repositioning logic executed...
2
by: Rodney Roe | last post by:
I'm using vba in excell 2007, and I wrote a program that through the FSO I can read/write data to a text file. I don't want my users to see said text file. Is there a way to use the FSO to textsream...
2
by: Molham | last post by:
How to show same text as hyperlink to other new tab page? <%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default2.aspx.vb" Inherits="Default2" %> <!DOCTYPE html PUBLIC "-//W3C//DTD...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.