Javascript - onblur problem

  • sarvel
  • Student
  • Student
  • User avatar
  • Posts: 79
  • Loc: Dubai

Post 3+ Months Ago

dear friends i have problem in onblur function in mozilla ,the code is working Perfectly in ie but in mozilla the onblur is not working.i want to generate the text box on the onblur .please help me




Code: [ Select ]
<td>
<input type="text" name="noofchoices" size="10" maxlength="1" value="1" onblur="return createRows()"/>
</td>

function createRows(){
        
        var noofchoices;
        noofchoices = edu.noofchoices.value;
        if((edu.noofchoices.value==""))
            noofchoices=0;
        var i=0;
        var rownum=choice.rows.length;
        if(noofchoices > rownum-1){
                noofchoices = noofchoices - (rownum-1);
                for(i=0;i<noofchoices;i++){
                    rownum=choice.rows.length;
                    
                    choice.insertRow(rownum);    
                    choice.rows(rownum).insertCell();                 
                    choice.rows(rownum).cells(0).innerHTML="Course Id ";
                    choice.rows(rownum).insertCell();
                    choice.rows(rownum).cells(1).colSpan="3";
                    choice.rows(rownum).cells(1).className=classname;
                    choice.rows(rownum).cells(1).innerHTML="<edu:select name='courseid' fieldlist='<%=courseids%>' noselect='true' />";
                }
            }
    }
  1. <td>
  2. <input type="text" name="noofchoices" size="10" maxlength="1" value="1" onblur="return createRows()"/>
  3. </td>
  4. function createRows(){
  5.         
  6.         var noofchoices;
  7.         noofchoices = edu.noofchoices.value;
  8.         if((edu.noofchoices.value==""))
  9.             noofchoices=0;
  10.         var i=0;
  11.         var rownum=choice.rows.length;
  12.         if(noofchoices > rownum-1){
  13.                 noofchoices = noofchoices - (rownum-1);
  14.                 for(i=0;i<noofchoices;i++){
  15.                     rownum=choice.rows.length;
  16.                     
  17.                     choice.insertRow(rownum);    
  18.                     choice.rows(rownum).insertCell();                 
  19.                     choice.rows(rownum).cells(0).innerHTML="Course Id ";
  20.                     choice.rows(rownum).insertCell();
  21.                     choice.rows(rownum).cells(1).colSpan="3";
  22.                     choice.rows(rownum).cells(1).className=classname;
  23.                     choice.rows(rownum).cells(1).innerHTML="<edu:select name='courseid' fieldlist='<%=courseids%>' noselect='true' />";
  24.                 }
  25.             }
  26.     }
  • rtm223
  • Mastermind
  • Mastermind
  • User avatar
  • Posts: 1855
  • Loc: Uk

Post 3+ Months Ago

Do you need the "return" in "return createrows"? I'm not exactly sure what would need returning?

What error do you get in mozilla (check the javascript console)
  • Carnix
  • Guru
  • Guru
  • User avatar
  • Posts: 1098

Post 3+ Months Ago

This might be a silly question... but...
Does Mozilla support the innerHTML method? That was an IE only method at one time (back in the nightmarish era of v4 browsers...)

*Edit: Oh, and rtm has a good question... since your function returns nothing, having return in the onBlur call there will ALWAYS return false, which might be interepreted by Mozilla as stop right there, don't render this. IE might be too lienient (or stupid, depending on your point of view) to do that.

.c
  • rtm223
  • Mastermind
  • Mastermind
  • User avatar
  • Posts: 1855
  • Loc: Uk

Post 3+ Months Ago

If no-one gives an answer by tomorrow morning (when i get home) I will consult the "big book of javascript" (thats just what I call the O'Reilly Definitive guide). I know there are a few varitions and that lists the compatibility, but that could very well be the reason.
  • RichB
  • Guru
  • Guru
  • User avatar
  • Posts: 1121
  • Loc: Boston

Post 3+ Months Ago

Mozilla does support innerHTML, but I think the problems here are twofold: the way objects are referred to in your script doesn't work in mozilla for me, and the use of parentheses instead of brackets in some locations is being interpreted by Mozilla as a function call instead of an index number. Instead of using names to identify the form and table I tried id's and used document.getElementById to retrieve references to the objects, and I replaced the parentheses with brackets where applicable and I think it's working now, although it's hard to tell from just code fragments. I also put classname inside quotes, so that mozilla wouldn't mistake it for an undefined variable (if it's a variable elsewhere in your script you won't want the quotes). For testing purposes, I replaced the tag inside cell[1] with "just a test" so it would be visible to me in the browser window.

This is the code that I came up with:

Code: [ Select ]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
<title>Untitled</title>
<script type="text/javascript">
<!--
function createRows(){
    var edu = document.getElementById('edu');
    var choice = document.getElementById('choice');
   var noofchoices;
   noofchoices = edu.noofchoices.value;
   if((edu.noofchoices.value==""))
     noofchoices=0;
   var i=0;
   var rownum=choice.rows.length;
   if(noofchoices > rownum-1){
      noofchoices = noofchoices - (rownum-1);
      for(i=0;i<noofchoices;i++){
        rownum=choice.rows.length;
        
        choice.insertRow(rownum);  
        choice.rows[rownum].insertCell(0);       
        choice.rows[rownum].cells[0].innerHTML="Course Id ";
        choice.rows[rownum].insertCell(1);
        choice.rows[rownum].cells[1].colSpan="3";
        choice.rows[rownum].cells[1].className="classname";
        choice.rows[rownum].cells[1].innerHTML="just a test";
      }
     }
  } 
// -->
</script>
</head>
<body>
<table id="choice">
<tr>
<td></td>
</tr>
</table>
<form id="edu">
<td>
<input type="text" name="noofchoices" size="10" maxlength="1" value="1" onblur="return createRows()"/>
</td>
</form>

</body>
</html>
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  2. <html>
  3. <head>
  4. <title>Untitled</title>
  5. <script type="text/javascript">
  6. <!--
  7. function createRows(){
  8.     var edu = document.getElementById('edu');
  9.     var choice = document.getElementById('choice');
  10.    var noofchoices;
  11.    noofchoices = edu.noofchoices.value;
  12.    if((edu.noofchoices.value==""))
  13.      noofchoices=0;
  14.    var i=0;
  15.    var rownum=choice.rows.length;
  16.    if(noofchoices > rownum-1){
  17.       noofchoices = noofchoices - (rownum-1);
  18.       for(i=0;i<noofchoices;i++){
  19.         rownum=choice.rows.length;
  20.         
  21.         choice.insertRow(rownum);  
  22.         choice.rows[rownum].insertCell(0);       
  23.         choice.rows[rownum].cells[0].innerHTML="Course Id ";
  24.         choice.rows[rownum].insertCell(1);
  25.         choice.rows[rownum].cells[1].colSpan="3";
  26.         choice.rows[rownum].cells[1].className="classname";
  27.         choice.rows[rownum].cells[1].innerHTML="just a test";
  28.       }
  29.      }
  30.   } 
  31. // -->
  32. </script>
  33. </head>
  34. <body>
  35. <table id="choice">
  36. <tr>
  37. <td></td>
  38. </tr>
  39. </table>
  40. <form id="edu">
  41. <td>
  42. <input type="text" name="noofchoices" size="10" maxlength="1" value="1" onblur="return createRows()"/>
  43. </td>
  44. </form>
  45. </body>
  46. </html>


When I run that code in both IE and Mozilla and enter 5 in the text box I get this onblur:

Code: [ Select ]
Course Id just a test
Course Id just a test
Course Id just a test
Course Id just a test
Course Id just a test
  1. Course Id just a test
  2. Course Id just a test
  3. Course Id just a test
  4. Course Id just a test
  5. Course Id just a test


If I then change it to 6 it will append just one more onblur, so I think it's working correctly, and I get no errors or warnings from the javascript console window..

//edit

I forgot to mention that I replace insertCell() with insertCell(0) and insertCell(1) as Mozilla seems to require an argument for that function.
  • sarvel
  • Student
  • Student
  • User avatar
  • Posts: 79
  • Loc: Dubai

Post 3+ Months Ago

:) hai friend
Now the coding is working,I am really happy thank u very much.

Post Information

  • Total Posts in this topic: 6 posts
  • Users browsing this forum: No registered users and 26 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.