472,325 Members | 982 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,325 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 2789
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....
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...
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. ...
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...
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...
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...
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...
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...
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...
0
by: tammygombez | last post by:
Hey fellow JavaFX developers, I'm currently working on a project that involves using a ComboBox in JavaFX, and I've run into a bit of an issue....
0
by: tammygombez | last post by:
Hey everyone! I've been researching gaming laptops lately, and I must say, they can get pretty expensive. However, I've come across some great...
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
0
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
0
by: CD Tom | last post by:
This happens in runtime 2013 and 2016. When a report is run and then closed a toolbar shows up and the only way to get it to go away is to right...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...

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.