473,385 Members | 1,320 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 and hidden when dropdown selected value change?

1
I'm using codeigniter to create my php web site in my view page I need to set visible when the drop-down value change how can i do that?
this the button that i need visible and hidden when drop-down change

dropdown
Expand|Select|Wrap|Line Numbers
  1.  <div class="form-group">
  2.          <label for="lastname" class="control-label">Your Packages</label>
  3.            <?php if(isset($tourbuddy_packages)){?>
  4.               <select id="itemType_id" class="form-control input-sm" name="tripbuddy_PackageTitle" >
  5.            <?php
  6.                 foreach ($tourbuddy_packages as $packages) {?>
  7.                    <option value="<?php echo $packages['PackageID'] ?> "><?php echo $packages['PackageTitle']?></option>
  8.             <?php } ?>
  9.             </select>
  10.             <input type="hidden" name="PackageID" id="country_hidden">
  11.              <?php }  else { ?>
  12.                 <select class="form-control input-sm" name="tripbuddy_PackageTitle">
  13.                     <option>Add Packages</option>
  14.                   </select>
  15.               <?php } ?>
  16. </div>
button
Expand|Select|Wrap|Line Numbers
  1. <button type="button" class="btn btn-default btn-sm" data-toggle="modal" data-target="#yourpackages" >View/Edit</button>
other than this i used some javascrip to send ajax request to my controller
Expand|Select|Wrap|Line Numbers
  1. $("#itemType_id").change(function() {
  2.  
  3.  
  4.             $.ajax({
  5.                 url : "feature/tea/",
  6.                 method: "post",
  7.                 data: "id=" + $(this).val(),
  8.                 dataType:"json",
  9.                 success: function(response) {
  10.                    window.location.reload();
  11.  
  12.                     // handle
  13.                 }
  14.             })  
  15.         });
Mar 31 '14 #1
1 5140
Sherin
77 64KB
Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>jQuery Show Hide Elements Using Select Box</title>
  6. <style>
  7.     .box{
  8.         color: #fff;
  9.         padding: 20px;
  10.         display: none;
  11.         margin-top: 20px;
  12.     }
  13.     .red{ background: #ff0000; }
  14.     .green{ background: #228B22; }
  15.     .blue{ background: #0000ff; }
  16. </style>
  17. <script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
  18. <script>
  19. $(document).ready(function(){
  20.     $("select").change(function(){
  21.         $(this).find("option:selected").each(function(){
  22.             var optionValue = $(this).attr("value");
  23.             if(optionValue){
  24.                 $(".box").not("." + optionValue).hide();
  25.                 $("." + optionValue).show();
  26.             } else{
  27.                 $(".box").hide();
  28.             }
  29.         });
  30.     }).change();
  31. });
  32. </script>
  33. </head>
  34. <body>
  35.     <div>
  36.         <select>
  37.             <option>Choose Color</option>
  38.             <option value="red">Red</option>
  39.             <option value="green">Green</option>
  40.             <option value="blue">Blue</option>
  41.         </select>
  42.     </div>
  43.     <div class="red box">You have selected <strong>red option</strong> so i am here</div>
  44.     <div class="green box">You have selected <strong>green option</strong> so i am here</div>
  45.     <div class="blue box">You have selected <strong>blue option</strong> so i am here</div>
  46. </body>
  47. </html>
  48.  
Aug 11 '20 #2

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

Similar topics

0
by: Kannan.M.R | last post by:
Hi, I have a problem in assigning the selected value in the dropdown to a hidden control. It goes like this. I have a repeater control. In the repeater control’s item template, I have a...
2
by: tmeister | last post by:
I must be missing something obvious. I have a drop down list in asp.net and it populates the states from a database. When I view the source of the page I get the standard option tags with the...
2
by: siaj | last post by:
Hi..Me New to ASP.NET I am trying to get the selected value from the dropdownlist but I m always getting the first selected value ...I am giving the code down ... <asp:dropdownlist...
6
by: itgaurav198 | last post by:
Hi, i have one jsp in which i select a value from drop down and on change of this a servlet is called that accesses some values and return to the same jsp where these values get populated in...
1
by: gopim | last post by:
i write the code like this function show() { var subject=document.getElementById('<%=ddlsubject.ClientID %>'); var txtsubject=document.getElementById('<%=TextBox1.ClientID%>');...
5
by: canajien | last post by:
I am trying to get a script to show a particular image when a field value = 1, otherwise it will show something else, and this is what I came up with: $i=0; while ($i < $num) { ...
3
by: jerrydigital | last post by:
good evening, I am trying to allow my users to enter in text if they don't find their option on my drop down menu. In the code below, I can get a text box to show up when I select 'Other' on the...
0
by: khushi patel | last post by:
I am working on Lightbox that has dropdown on it. depending on ddl value div should be shown up pleae help <%@ Page Title="" Language="VB" MasterPageFile="~/MasterSite.master"...
1
by: kunal choudhary | last post by:
hi, I have created a form (in ASP.NET and C#) which have 5 dropdown 1.3rd dropdown fill on the basis of 1st n 2nd dropdown value 2.5th dropdown fill on the basis of 4th dropdown value I...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

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.