473,385 Members | 1,661 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.

Making the option as selected based on the specfic value

hai friends

i am doing my updating page their i have one select field i am getting the input from the user and saved the select field value alone in the db . now based on the select value from the db the select field option should be displayed in the page .that means the option displayed on the page should change based on the db value . how can i change based on the db value as selected in the select field?.

thanks in advance

sivaani.j
Feb 26 '08 #1
1 888
gits
5,390 Expert Mod 4TB
assuming you have a select like the following:

[HTML]<select id="my_select">
<option value="A">A</option>
<option value="B">B</option>
<option value="C">C</option>
</select>
[/HTML]
you could use a function like this:

Expand|Select|Wrap|Line Numbers
  1. function select_opt_by_val(obj, val) {
  2.     var opts = obj.getElementsByTagName('option');
  3.  
  4.     for (var i = 0, n; n = opts[i]; i++) {
  5.         if (n.value == val) {
  6.            n.selected = true;
  7.            break;
  8.         }
  9.     }
  10. }
  11.  
  12. var s = document.getElementById('my_select');
  13.  
  14. select_opt_by_val(s, 'C');
  15.  
kind regards
Feb 26 '08 #2

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

Similar topics

0
by: |-|erc | last post by:
Hi! Small challenge for you. The index.php uses this file and calls layout(). Take a look at www.chatty.net this file draws the chat login box on the right. I traced the CHAT button it submits...
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...
6
by: Arthur | last post by:
Hello. How might it be possible to change where a form action is directed based on a selected option. For example I have this: <FORM METHOD = "post" ACTION = ""> And a drop down such as
3
by: Venturini | last post by:
I am trying to put together a web page where the customer makes choices of products and is then given a total. I am extremely new to Javascript and have managed to get as far as I have from web...
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: 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: 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:
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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.