By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,365 Members | 1,246 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,365 IT Pros & Developers. It's quick & easy.

Any one please help me by seeing this code

P: 29
This is the code i hav written
in this i hav to call the respective functions
whenever i press a tab using onblur function
please help me......................




[HTML]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<script type="text/javascript">
<!--
function changePage(newLoc)
{
nextPage = newLoc.options[newLoc.selectedIndex].value
if (nextPage == "month")
{
window.alert("Enter MONTH");
document.demo.selectedPage.focus();
}
}
function change1Page(newLoc1)
{
nextPage1=newLoc1.options[newLoc1.selectedIndex].value
if(nextPage1=="date")
{
window.alert("Enter DATE");
document.demo.selected1Page.focus();
}
}
function change2Page(newLoc2)
{
nextPage2=newLoc2.options[newLoc2.selectedIndex].value
if(nextPage2=="year")
{
window.alert("Enter YEAR");
document.demo.selected2Page.focus();
}
}
-->
</script>
</head>
<body>
<form name="demo">
Date Of Birth: <select name="selectedPage"
onblur="changePage(document.demo.selectedPage)">
<option value="month" selected="selected">select month</option>
<option>Jan</option>
<option>Feb</option>
<option>Mar</option>
<option>Apr</option>
<option>May</option>
<option>Jun</option>
<option>Jul</option>
<option>Aug</option>
<option>Sep</option>
<option>Oct</option>
<option>Nov</option>
<option>Dec</option>
</select>
<select name="selected1Page" onblur="change1Page(document.demo.selected1Page)">
<option value="date" selected="selected">select date</option>
<option>1</option><option>2</option><option>3</option><option>4</option><option>5</option><option>6</option><option>7</option>
<option>8</option><option>9</option><option>10</option><option>11</option><option>12</option><option>13</option><option>14</option><option>15</option><option>16</option><option>17</option><option>18</option><option>19</option><option>20</option>
<option>21</option><option>22</option><option>23</option><option>24</option><option>25</option><option>26</option>
<option>27</option><option>28</option><option>29</option><option>30</option><option>31</option>
</select>
<select name="selected2Page" onblur="change2Page(document.demo.selected2Page)">
<option value="year" selected="selected">select year</option>
<option>1955</option><option>1956</option><option>1957</option><option>1958</option><option>1959</option><option>1960</option>
<option>1961</option><option>1962</option><option>1963</option><option>1964</option><option>1965</option><option>1966</option>
<option>1967</option><option>1968</option><option>1969</option><option>1970</option><option>1971</option><option>1972</option>
<option>1973</option><option>1974</option><option>1975</option><option>1976</option><option>1977</option><option>1978</option><option>1979</option><option>1980</option><option>1981</option><option>1982</option><option>1983</option><option>1984</option>
<option>1985</option><option>1986</option><option>1987</option><option>1988</option><option>1989</option><option>1990</option>
</select>
</form>
</body>
</html>[/HTML]
Feb 21 '07 #1
Share this Question
Share on Google+
6 Replies

acoder
Expert Mod 15k+
P: 16,027
Instead of onblur why not use onchange?
Feb 21 '07 #2

P: 29
Ok thank you
i know the functionality of onchange
just i want to know whether we can go with onblur r not as i hav specified in the code.
Feb 23 '07 #3

acoder
Expert Mod 15k+
P: 16,027
Well, should not use onblur which can cause problems (because it might be caused by something other than a tab key press). What you can do instead is detect the tab key by setting the onkeyup event handler. The key code is 9 for tab.

I, however, would suggest that you use onchange instead because it only detects when the user makes a change. You can always make a final check when the user tries to submit the form.

btw, this is when you are using alert boxes. If you are just displaying a string error message next to the element, it might be ok. Note that changing the default behaviour (moving focus to the next element) can cause problems.
Feb 23 '07 #4

P: 29
k thank u for ur suggestion
Feb 23 '07 #5

dmjpro
100+
P: 2,476
i also have that problem ...

a best suggestion i was waiting for === acoder

looootttttt of thanxxxxxxx
Feb 24 '07 #6

acoder
Expert Mod 15k+
P: 16,027
Both of you are welcome. Glad it helped you.
Feb 26 '07 #7

Post your reply

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