Do not use on any
shared computer
July 24, 2008 08:35pm pdt
null
[x]
Attachment Details

Firefox, Javascript onBlur, onChange, onFocus Problems

Tags: firefox, javascript, onblur, onchange, onfocus
OnBlur and OnFocus Events not working in FIreFox.  This is a known issue, but I've heard of some workarounds to certain situations, and I'm hoping that one of you may have the answer for my problem.

In my forms, I am combining several form fields into 1 field or storage into a database.

Example:
Dropdowns for Day, Month, Year.  I use an onBlur or onChange to call a javascript function that formats the date as 0000-00-00 and stores it to it's own variable to be stored in a database.

This method is fine in all browsers except Firefox.  Apparently, Firefox has issues with how the onblur or onchange is handled and never updates the variable, and furthermore, loses its focus to the previous text field.

I will post several examples of what I have tried.

[code]
<script language="JavaScript"><!--
function birthdayBuild() {
     document.form.birthday.value =  document.form.byear.value + '-' + document.form.bmonth.value + '-' + document.form.bday.value;
}
function hometownBuild() {
     document.form.hometown.value =  document.form.city.value + '|' + document.form.state.value + '|' + document.form.country.value;
}
function schoolBuild() {
     document.form.schools.value =  document.form.school1.value + '|' + document.form.school2.value + '|' + document.form.school3.value;
}
//--></script>

///////////////////////////////FIRST METHOD/////////////////////////////////////////////////
 <select name="bmonth" class="month" id="bmonth" onBlur="birthdayBuild();">
<option value="01">January</option>
        <option value="02">February</option>
        <option value="03">March</option>
        <option value="04">April</option>
        <option value="05">May</option>
        <option value="06">June</option>
        <option value="07">July</option>
        <option value="08">August</option>
        <option value="09">September</option>
        <option value="10">October</option>
        <option value="11">November</option>
        <option value="12">December</option>
      </select>
      <select name="bday" class="dateyear" id="bday" onBlur="birthdayBuild();">
        <?
        for ($i = 1; $i <= 31; $i++)
        {
        ?>
        <option value="<? echo $i; ?>" ><? echo $i; ?></option>
        <?
            }
       ?>
      </select>
      <select name="byear" class="dateyear" id="byear" onBlur="birthdayBuild();" >
         <?
        for ($i = 2007; $i >= 1900; $i--)
         {
        ?>
        <option value="<? echo $i; ?>" ><? echo $i; ?></option>
        <?
            }
       ?>
      </select>
        <input type="hidden" name="birthday">

///////////////////////////////SECOND METHOD/////////////////////////////////////////////////
 <input name="city" type="text" class="textfield3" id="city" onfocus="document.getElementById(city).blur()" onChange="hometownBuild();">
      <select name="state" class="dateyear" id="state" onfocus="document.getElementById(state).blur()" onChange="hometownBuild();">
    <option value="AL">AL</option>
      <option value="AK">AK</option>
      <option value="AZ">AZ</option>
      <option value="AR">AR</option>
      <option value="CA">CA</option>
</select>
      <input name="country" type="text" class="textfield3" id="country" onfocus="document.getElementById(country).blur()" onChange="hometownBuild();">
        <input type="hidden" name="hometown">

///////////////////////////////THIRD METHOD/////////////////////////////////////////////////
      <input name="city" type="text" class="textfield3" id="city" onChange="hometownBuild();" onfocus="this.blur()">
      <select name="state" class="dateyear" id="state" onChange="hometownBuild();" onfocus="this.blur()">
      <option value="AL">AL</option>
      <option value="AK">AK</option>
      <option value="AZ">AZ</option>
      <option value="AR">AR</option>
      <option value="CA">CA</option>
</select>
      <input name="country" type="text" class="textfield3" id="country" onChange="hometownBuild();" onfocus="this.blur()">
        <input type="hidden" name="hometown">
[/code]

Plug this into a firefix browser and you'll see what I mean.


Start your free trial to view this solution
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

Question Stats
Zone: Software
Question Asked By: MrBaseball9
Solution Provided By: ncoo
Participating Experts: 2
Solution Grade: A
Views: 453
Translate:
Loading Advertisement...
 
[+][-]Expert Comment by ncoo
Expert Comment by ncoo:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Expert Comment by ncoo
Expert Comment by ncoo:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Author Comment by MrBaseball9
Author Comment by MrBaseball9:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Author Comment by MrBaseball9
Author Comment by MrBaseball9:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Expert Comment by walkerke
Expert Comment by walkerke:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Author Comment by MrBaseball9
Author Comment by MrBaseball9:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Author Comment by MrBaseball9
Author Comment by MrBaseball9:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Expert Comment by ncoo
Expert Comment by ncoo:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Author Comment by MrBaseball9
Author Comment by MrBaseball9:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Accepted Solution by ncoo
Accepted Solution by ncoo:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Author Comment by MrBaseball9
Author Comment by MrBaseball9:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Expert Comment by ncoo
Expert Comment by ncoo:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
Loading Advertisement...
20080723-EE-VQP-34