473,378 Members | 1,175 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,378 software developers and data experts.

Dropdown box with onchange() in javascript

Hi,
i'm trying to write javascript code for "changing the webpage contents whenever i'm selecting one option in dropdown box, like if dropdown box is there with options a,b,c,d... then when i select 'a', one table for 'a' should display and when i select 'b', one table for 'b' should display on the same page".

that is i want plz any one of u post Answr to this Question.

Thanking you
Dec 1 '07 #1
4 2266
Markus
6,050 Expert 4TB
If you can write some of the code yourself and prove that we wouldn't be writing this just to help you through some exam, then i'd be happy to help.

But until you do so, read some tutorials.
Dec 1 '07 #2
acoder
16,027 Expert Mod 8TB
i'm trying to write javascript code for "changing the webpage contents whenever i'm selecting one option in dropdown box, like if dropdown box is there with options a,b,c,d... then when i select 'a', one table for 'a' should display and when i select 'b', one table for 'b' should display on the same page".
Hide all the tables and display the required one onchange. Show your code.
Dec 1 '07 #3
If you can write some of the code yourself and prove that we wouldn't be writing this just to help you through some exam, then i'd be happy to help.

But until you do so, read some tutorials.
-----------------------------------------------------------------------------------------------------------------------
Hi markusn00b,
yaa i'm sorry , i didnt send the code. okay this is my code just look into it. Where should i write code to display tables according to selected options and how to write . plz help me.
Expand|Select|Wrap|Line Numbers
  1. <body>
  2. <script language="javascript" type="text/javascript">
  3. function switchpage(select) 
  4. {
  5.     var index;
  6.     var global;    
  7.     alert("No.of options "+select.options.length+" ");
  8.  
  9.     for(index=0; index < select.options.length; index++)
  10.     {
  11.         if(select.options[index].selected)
  12.         {
  13.             if(select.options[index].value != "")
  14.             {
  15.                 global = select.options[index].value;
  16.                 alert("Selected "+global+" ");
  17.                 break;              
  18.             }
  19.         }
  20.     }
  21.     if(global=="a")
  22.     {
  23.         alert("this is A");
  24.         // code for displaying one table for 'a'
  25.     }
  26.     if(global=="b")
  27.     {    
  28.         alert("this is B");
  29.         // code for displaying one table for 'b'
  30.     }    
  31. }
  32. </script>
  33. <form method="post">
  34. <select name="url" onchange=switchpage(this)>
  35.     <option value="a">a</option>
  36.     <option value="b">b</option>
  37.     <option value="c">c</option>
  38.     <option value="d">d</option>
  39. </select>Select
  40. </form>
  41. </body>
  42.  
Dec 2 '07 #4
acoder
16,027 Expert Mod 8TB
Put the tables where you need them to appear on the page and keep them hidden:
[HTML]<table ... style="display:none">[/HTML] then show them by setting the style.display property to "block".

By the way, you can just use select.value to get the selected value rather than using a for loop.
Dec 2 '07 #5

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

Similar topics

2
by: Mark Durgee | last post by:
I have a "submit" button in a form that creates a record in my Filemaker database that works as it should. This is the HTML for it: <INPUT TYPE="SUBMIT" name="-New" VALUE="Add Record"> I...
1
by: middletree | last post by:
For an ASp Intranet app, I have some code that should work, but I am not able to make it happen for some reason, after spending considerable time on this. I am pretty thick when it comes to...
3
by: Jon | last post by:
I am using cascading dropdowns, where the selection in one determines what fills another. In regular ASP I simply loaded a giant dataset into javascript array and when you clicked on one dropdown,...
3
by: DaveF | last post by:
I need to capture a selected value of the onchange dropdown and put it in a textbox??? -- Dave
7
by: =?Utf-8?B?Qw==?= | last post by:
I have a dropdown list as below. I add an onchnage attribute in my codebehind to call some Javascript. I want to get the selected text from my dropdown. What am I doing wrong below? ...
4
by: J MCallister | last post by:
Hello, I am working on a shopping cart where the viewer sees a dropdown with shipping options, each with a price. Elsewhere on the page is a display of the total. I am working on having the...
1
by: madhusudangosula | last post by:
I need onchange in javascript for two dropdown list.. I have two dropdown list 1.Activity Type 2.Category At present both are independent to each other... Now the thing is i need to map...
4
by: zion4ever | last post by:
Hello good people, Please bear with me as this is my first post and I am relative new to ASP. I do have VB6 experience. I have a form which enables users within our company to do an intranet...
11
by: tokcy | last post by:
Hi everyone, I am new in php and ajax, i am facing the prob while i click on element of first drop down then in second dropdown all element showl come from database. I mean i have three dropdown 1....
16
by: tarunkhatri | last post by:
Hi. I have a javascript function to change the value of the cell on chnage event of a dropdown list.My code is workin but the problem is that the value of the cell is chaning but not respective to...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.