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

Display the selected item

Ranjan kumar Barik
Hello !!!

I am Ranjan.

can the selected item of a combo box be displayed on the same page.
I mean when I just click the item of a combo box it will atonce displayed on the page.

Thanks !!!
Aug 28 '07 #1
16 2963
markrawlingson
346 Expert 100+
This is easy to accomplish with javascript.

Place the following code within your < select > tag

onChange="javascript:document.getElementById('myId ').innerText=this.options[this.selectedIndex].value;"

Modify the Id of the object where you wish the content to be placed as necessary, of course.

For example...

<select name="whatever" id="whatever" onChange="javascript:document.getElementById('myId ').innerText=this.options[this.selectedIndex].value;">
<option value="whatever1">Whatever1</option>
<option value="whatever1">Whatever1</option>
<option value="whatever1">Whatever1</option>
<option value="whatever1">Whatever1</option>
<option value="whatever1">Whatever1</option>
</select>

and have a layer, like a div or span tag, present on the page
<div id="myId"></div>
Aug 28 '07 #2
This is easy to accomplish with javascript.

Place the following code within your < select > tag

onChange="javascript:document.getElementById('myId ').innerText=this.options[this.selectedIndex].value;"

Modify the Id of the object where you wish the content to be placed as necessary, of course.

For example...

<select name="whatever" id="whatever" onChange="javascript:document.getElementById('myId ').innerText=this.options[this.selectedIndex].value;">
<option value="whatever1">Whatever1</option>
<option value="whatever1">Whatever1</option>
<option value="whatever1">Whatever1</option>
<option value="whatever1">Whatever1</option>
<option value="whatever1">Whatever1</option>
</select>

and have a layer, like a div or span tag, present on the page
<div id="myId"></div>
Hello !!!
You have sended me a very good script.
But I am sorry to mention that I actually trying it in an "asp file" using "vbscript"
So I am sorry again.
Still I need your help.

Thankssssss !!!!
Aug 29 '07 #3
jhardman
3,406 Expert 2GB
Hello !!!
You have sended me a very good script.
But I am sorry to mention that I actually trying it in an "asp file" using "vbscript"
So I am sorry again.
Still I need your help.

Thanks!
Ranjan,

vbscript and javascript are not mutually exclusive. ASP scripts are run on the server so only function when the page is loading, and mark is suggesting you add client-side scripting. The most well-supported client-side script is javascript and his example would work well for your purpose.

Jared
Aug 29 '07 #4
Ranjan,

vbscript and javascript are not mutually exclusive. ASP scripts are run on the server so only function when the page is loading, and mark is suggesting you add client-side scripting. The most well-supported client-side script is javascript and his example would work well for your purpose.

Jared
Hello Jhardman !!!

I have used the script and it works well.
I just have done it like this ;


<%
dim str
str = "select india pakistan bangladesh usa uk china indonesia southAfrica"
dim country
country = split(str," ")
dim c
c=ubound(country)

response.write("<form><select name=cbo onchange=javascript:document.getElementById('myId' ).innerHTML=this.value;>")
for i=0 to c
response.write("<option value="&country(i)&">"+Cstr(country(i)))
response.write("</option>")
next
response.write("</select></form>")
%>

But in this case one problem is that when I open view soure on the page I found that there is nothing inside the <div> section.I just want to make it visible.

ThankSSSSSSSS !!!!!!
Aug 30 '07 #5
markrawlingson
346 Expert 100+
The div container holds dynamically generated content on the client side, but is initialized as empty when you write the script - so if you open the source you won't see anything in the div container. That's normal.
Aug 30 '07 #6
The div container holds dynamically generated content on the client side, but is initialized as empty when you write the script - so if you open the source you won't see anything in the div container. That's normal.
Its true that the container has dynamically generated content.
>>Is there any way to do it before the container is being inisialised.

>>>that is the asp file would generate an html file where I can see the combo box selected and the selected item is also displayed.I hope you understand.
Aug 31 '07 #7
jhardman
3,406 Expert 2GB
Its true that the container has dynamically generated content.
>>Is there any way to do it before the container is being inisialised.

>>>that is the asp file would generate an html file where I can see the combo box selected and the selected item is also displayed.I hope you understand.
If I understand you right, what you actually want to do is submit the form when an option from the select box is selected, then the form handler sends back to the browser an almost identical page, but with the div added on. This is doable, I have seen it done to good effect. just put an onChange attribute on the select control which submits the form, and resend the page with all of their inputs filled out. does this make sense?

Jared
Aug 31 '07 #8
If I understand you right, what you actually want to do is submit the form when an option from the select box is selected, then the form handler sends back to the browser an almost identical page, but with the div added on. This is doable, I have seen it done to good effect. just put an onChange attribute on the select control which submits the form, and resend the page with all of their inputs filled out. does this make sense?

Jared
I have submitted the form using onchange event.But I could not make out how to resend the page with filled out combobox and simultaneously the <div> will be displayed.
Sep 1 '07 #9
markrawlingson
346 Expert 100+
It's different for each type of form element..

For texboxes - <input type="text" name="atextbox" value="<%=Request.Form("atextbox")%>"> - basically you're grabbing the content from itself.

To fill the div...

Expand|Select|Wrap|Line Numbers
  1. <div id="whatever">
  2. <%=Request.Form("yourselectbox")%>
  3. </div>
  4.  
Select boxes, radio buttons, and check boxes are a little trickier because their default value is "CHECKED" (radio buttons) and "SELECTED" (Select boxes)

I usually create a function for writing out select boxes, because then it's very straight forward.. otherwise you have to write out :

Expand|Select|Wrap|Line Numbers
  1. <% if request.form("thisbox") = "this value" Then Response.write "SELECTED" end if %>
  2.  
For each and every option box. Same thing for radio button options.
Sep 1 '07 #10
It's different for each type of form element..

For texboxes - <input type="text" name="atextbox" value="<%=Request.Form("atextbox")%>"> - basically you're grabbing the content from itself.

To fill the div...

Expand|Select|Wrap|Line Numbers
  1. <div id="whatever">
  2. <%=Request.Form("yourselectbox")%>
  3. </div>
  4.  
Select boxes, radio buttons, and check boxes are a little trickier because their default value is "CHECKED" (radio buttons) and "SELECTED" (Select boxes)

I usually create a function for writing out select boxes, because then it's very straight forward.. otherwise you have to write out :

Expand|Select|Wrap|Line Numbers
  1. <% if request.form("thisbox") = "this value" Then Response.write "SELECTED" end if %>
  2.  
For each and every option box. Same thing for radio button options.
Hello mark!!!
I am writting the code i have used.Please tell me what more changes I need to make the combox box selected after submission.

------------CODE--------------

<html>
<head><title>dpd</title></head>
<body>

<%
dim str
str = "select india pakistan bangladesh usa uk china indonesia southAfrica"
dim country
country = split(str," ")
dim c
c=ubound(country)

response.write("<form id=frm action=dpd.asp method=post><select name=cbo onchange=frm.submit()>")
for i=0 to c
response.write("<option value="&country(i)&">"+Cstr(country(i)))
response.write("</option>")
next
response.write("</select></form>")
%>

<div id="mydiv">
<%=request.form("cbo")%>
</div>

</body>
</html>

------------END-------------------

Thnaks !!!!!!
Sep 3 '07 #11
markrawlingson
346 Expert 100+
Give this a shot, pretty self explanitory.

Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head><title>dpd</title></head>
  3. <body>
  4.  
  5. <%
  6. dim str
  7. str = "select india pakistan bangladesh usa uk china indonesia southAfrica"
  8. dim country
  9. country = split(str," ")
  10. dim c
  11. c=ubound(country)
  12.  
  13. response.write("<form id=frm action=dpd.asp method=post><select name=cbo onchange=frm.submit()>")
  14. for i=0 to c
  15. If Request.Form("cbo") = country(i) Then
  16. IsSelected = " SELECTED"
  17. End If
  18. response.write("<option value="&country(i)&IsSelected&">" & Cstr(country(i)))
  19. response.write("</option>")
  20. next
  21. response.write("</select></form>")
  22. %>
  23.  
  24. <div id="mydiv">
  25. <%=request.form("cbo")%>
  26. </div>
  27.  
  28. </body>
  29. </html>
  30.  
That should do the trick.
Sep 3 '07 #12
Give this a shot, pretty self explanitory.

Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head><title>dpd</title></head>
  3. <body>
  4.  
  5. <%
  6. dim str
  7. str = "select india pakistan bangladesh usa uk china indonesia southAfrica"
  8. dim country
  9. country = split(str," ")
  10. dim c
  11. c=ubound(country)
  12.  
  13. response.write("<form id=frm action=dpd.asp method=post><select name=cbo onchange=frm.submit()>")
  14. for i=0 to c
  15. If Request.Form("cbo") = country(i) Then
  16. IsSelected = " SELECTED"
  17. End If
  18. response.write("<option value="&country(i)&IsSelected&">" & Cstr(country(i)))
  19. response.write("</option>")
  20. next
  21. response.write("</select></form>")
  22. %>
  23.  
  24. <div id="mydiv">
  25. <%=request.form("cbo")%>
  26. </div>
  27.  
  28. </body>
  29. </html>
  30.  
That should do the trick.
Sorry mark
It just making the last item selected that is "southafrica" after submission.
Sep 3 '07 #13
markrawlingson
346 Expert 100+
Is that not the effect that you wanted? It will auto select whatever the user selects and re-post it back to itself.

If that was not the desired effect, please reply and be more clear and concise with what it is you want to do exactly.

Mark
Sep 3 '07 #14
Is that not the effect that you wanted? It will auto select whatever the user selects and re-post it back to itself.

If that was not the desired effect, please reply and be more clear and concise with what it is you want to do exactly.

Mark
I just want that when I select india the form will be submitted and the value india will remain selected and the division showing india also.

Same for all the other items.

Thanksssssss!!
Sep 3 '07 #15
markrawlingson
346 Expert 100+
Oh My bad.. I ran the code and see the mistake.

Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head><title>dpd</title></head>
  3. <body>
  4.  
  5. <%
  6. dim str
  7. str = "select india pakistan bangladesh usa uk china indonesia southAfrica"
  8. dim country
  9. country = split(str," ")
  10. dim c
  11. c=ubound(country)
  12.  
  13. response.write("<form id=frm action=dpd.asp method=post><select name=cbo onchange=frm.submit()>")
  14. for i=0 to c
  15. If Request.Form("cbo") = country(i) Then
  16. IsSelected = " SELECTED"
  17. else
  18. IsSelected = Empty
  19. End If
  20. response.write("<option value="&country(i)&IsSelected&">" & Cstr(country(i)))
  21. response.write("</option>")
  22. next
  23. response.write("</select></form>")
  24. %>
  25.  
  26. <div id="mydiv">
  27. <%=request.form("cbo")%>
  28. </div>
  29.  
  30. </body>
  31. </html>
  32.  
That should work now!
Sep 3 '07 #16
Oh My bad.. I ran the code and see the mistake.

Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head><title>dpd</title></head>
  3. <body>
  4.  
  5. <%
  6. dim str
  7. str = "select india pakistan bangladesh usa uk china indonesia southAfrica"
  8. dim country
  9. country = split(str," ")
  10. dim c
  11. c=ubound(country)
  12.  
  13. response.write("<form id=frm action=dpd.asp method=post><select name=cbo onchange=frm.submit()>")
  14. for i=0 to c
  15. If Request.Form("cbo") = country(i) Then
  16. IsSelected = " SELECTED"
  17. else
  18. IsSelected = Empty
  19. End If
  20. response.write("<option value="&country(i)&IsSelected&">" & Cstr(country(i)))
  21. response.write("</option>")
  22. next
  23. response.write("</select></form>")
  24. %>
  25.  
  26. <div id="mydiv">
  27. <%=request.form("cbo")%>
  28. </div>
  29.  
  30. </body>
  31. </html>
  32.  
That should work now!
Thanks a lot mark !!!!!!
You donot believe for consicutive 4 days I am working on this.
Thank you very much !
HaaaaaaVe a good day............
Sep 4 '07 #17

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

Similar topics

3
by: shreddie | last post by:
Could anyone assist with the following problem? I'm using JavaScript to hide/show table rows depending on the option selected in radio buttons. The script works fine in IE but in Firefox the...
3
by: Northern | last post by:
I need to write code clear the display box of my DropDownList (something like clear current selected item) while still keep the loaded item list in the DropDownList. I tried DropDownList's...
10
by: dhnriverside | last post by:
Hi guys Still having a problem with this dropdownlist. Basically, I've got 4. The first 2 work fine, then my code crashes on the 3rd. ddlEndTimeHour.Items.FindByValue(endTime).Selected =...
4
by: cwoll | last post by:
I am runing this function to toggle buttens to display an "X" when they is selected, the butten is linked to a yes/no field. This function works good, the problem I am having is that when I make a...
3
by: rukkie | last post by:
I've made a webform in which some selection boxes are incorporated. Once the form is submitted the user can display the form again and all the options selected are highlighted (via the "selected"...
1
by: Bob | last post by:
Hi, Hope you can help me with this one. I'm at my wits end. I'm trying to create an intelligent edit-box like the excellent "Customer" one at the URL: ...
3
by: =?Utf-8?B?TWFyayBCb2V0dGNoZXI=?= | last post by:
I am writing a Windows Form app in c# and I've populated a combobox with values. I click on the down arrow to display the list and the list of values displays correctly. Once I select a value,...
2
vikas251074
by: vikas251074 | last post by:
I am creating an application for official use. This application will be used by employees to take items for official use. I have a list, presently this list contains three items - 1) Cartridges, ...
2
by: kurtzky | last post by:
i created a form that should function as follows: i will enter a number in a textbox..then it should query from the database all the records which has that number..these records will have a...
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: 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...
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.