473,471 Members | 2,613 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How to give focus on List box .

Vini171285
60 New Member
Hi friends,

how to give focus on list box using javascript in ASP....
actually i could give focus on the list box...but after clicking the alert button,it focuses on the list box,,,and before doing any change it immediately passes to the next page...
Please guide me to avoid this problem...!!

Thanx in Advance!!
Apr 11 '08 #1
7 1595
DrBunchman
979 Recognized Expert Contributor
Hi Vini171285,

Can you give an example of your code please so we can see what you've done so far.

Dr B
Apr 11 '08 #2
Vini171285
60 New Member
Hi DrBunchman
This is my code.My problem is if listbox is not selected there shd be a alert msg,and focus shd go on the listbox.But after alert msg is clicked,next page is immediately loaded and listbox remains empty.
Code:
<script type="text/javascript">
function validate_listbox()
{
var x=document.getElementById("city");
if(x.options[x.selectedIndex]==0)
{
alert("Select a City");
document.getElementById("city").focus();
return false;
}
}
</script>
Apr 12 '08 #3
DrBunchman
979 Recognized Expert Contributor
When you call your Javascript do you use a return? e.g.

Expand|Select|Wrap|Line Numbers
  1. <input type="submit" value="Submit Form" OnClick="return validate_listbox()" />
You should put an else in your function which returns true as well. Like this:

Expand|Select|Wrap|Line Numbers
  1. function validate_listbox() 
  2. {
  3. var x=document.getElementById("city");
  4. if(x.options[x.selectedIndex]==0)
  5. {
  6. alert("Select a City");
  7. document.getElementById("city").focus();
  8. return false;
  9. }
  10. else
  11. {
  12. return true;
  13. }
  14. }
  15.  
Does this help?

Dr B
Apr 12 '08 #4
Vini171285
60 New Member
actually i could give focus on the list box...but after clicking the alert button,it focuses on the list box,,,and before doing any change it immediately passes to the next page...
This is my problem...
Apr 15 '08 #5
DrBunchman
979 Recognized Expert Contributor
Did you try putting a 'return' in as I suggested in my previous post? If not please try it and if so please print the code that you are using now.

Dr B
Apr 15 '08 #6
Vini171285
60 New Member
Hi
Thanx..
Return statement is Working...
Thank You...
Apr 15 '08 #7
DrBunchman
979 Recognized Expert Contributor
No problem, glad to be of help.

Dr B
Apr 15 '08 #8

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

Similar topics

2
by: N/A | last post by:
Hey all, If I open a popup like this window.open('http://www.google.com', 'popup', 'width = 618, height = 425, directories = no, location = no, menubar = no, resizable = no, scrollbars = yes,...
2
by: Paul Thompson | last post by:
I am trying to use various javascript tools, all of which work in NN, to work in IE. Here's my latest annoyance. I get a list of all objects on a page using docContents =...
0
by: Stephen Bedford | last post by:
I am developing an application that is primarily keyboard not mouse driven. Navigation is very difficult within some controls (list boxes, radio groups etc) unless the focus rectangle is visible. ...
2
by: Christian Ista | last post by:
Hello, I found that (see below) to give the focus to a control(textbox) on an asp.net page. There is no easiest way to do that ? Thanks, System.Text.StringBuilder sb = new...
4
by: PK9 | last post by:
I have a button at the top of my page that I have an onClick event handler for which makes some new controls (at the bottom of my page) visible. When the user clicks the button I make the new...
3
by: Roger Withnell | last post by:
Is it possible to test if a window or frame is in focus? Posted Via Usenet.com Premium Usenet Newsgroup Services ---------------------------------------------------------- ** SPEED **...
5
by: LabGeek | last post by:
I have an Access application that I have created that collects data from a scanner and from a weighting scale. The data from the scanner are unique identifiers (barcodes) and the scanner is...
0
by: =?Utf-8?B?SWdvcg==?= | last post by:
Hi everyone! I have some strange behavior of ListView control in WPF. We are developing application in C#. I created ListView with some items and set SelectedIndex to some index in the...
1
by: alivip | last post by:
I integrat program to be GUI using Tkinter I try browser direction as you can see # a look at the Tkinter Text widget # use ctrl+c to copy, ctrl+x to cut selected text, # ctrl+v to...
2
Vini171285
by: Vini171285 | last post by:
Hi friends, how to give focus on list box using javascript in ASP.... actually i could give focus on the list box...but after clicking the alert button,it focuses on the list box,,,and before...
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.