Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    New Coder
    Join Date
    Jul 2002
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Problem with onBlur in frame in Netscape- Veryvery urgent

    Hi,

    I am facing a problem with onBlur function in a frame in netscape.

    I have html file

    frame.html


    This html file containe 2 frames space.html,splitme.html


    Here is the code

    frame.html
    ************
    <html>
    <head>
    </head>
    <frameset rows="50,50">
    <frame src="split.html">
    <frame src="space.html">
    </frameset>
    </html>

    *****************
    space.html
    *****************

    <html>
    <head>
    <script>
    function CheckIt(X,ABC){
    a=0;
    FL=ABC.slice(0,1);
    LL=ABC.slice(ABC.length-1,ABC.length);
    if(FL==" "){ABC=ABC.slice(1,ABC.length);a=1;}
    if(LL==" "){ABC=ABC.slice(0,ABC.length-1);a=1;}
    X.value=ABC;
    if(a!=0){CheckIt(X,ABC)}
    }
    function stripSpace(obj)
    {
    var text = obj.value.replace(/^[\s]/,'');
    obj.value = text;
    }
    </script>


    </head>
    <body>
    <form name="FormName">
    <input type="text" onBlur="javascript:alert('Hifromsecondframe')" name="AName" size="12">
    <input type="text" onBlur="javascript:alert'Hellofromsecondframe')" name="AName" >
    </form>
    </body>
    </html>
    ***********************
    splitme.html
    *****************
    <html>
    <head>

    </head>
    <body>
    <form name=temp>
    <input type="hidden" name="hiddenValue" value="22">
    <input type="text" name="hiddenIndex" value="0,1,2,">
    <a href="java script:selectagbrwin()";>Select One</a>
    <a href="java script:alert(splitMe());">Test</a>
    <input type="text" name="a1" >
    <input type="text" name="a2" >
    </form>

    </body>
    </html>


    **************

    what happens in netscape is that after the 2 frames are loaded

    when i place the focus in the first textbox in the second frame and after that when click outside the document the onBlur event is called and the alert comes but in an infinite loop.same thing nhappens if i place the cursor in the nsecond textbox and click outside the alert comes in an infinite loop.Is it due to frames or some opther problem.Everything is fine with IE

    Thanks
    learner

  • #2
    Senior Coder
    Join Date
    Jun 2002
    Location
    Wichita
    Posts
    3,880
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Try:

    [code]
    <input type="text" onBlur="alert('Hifromsecondframe');return true;" name="AName" size="12">
    <input type="text" onBlur="alert'Hellofromsecondframe');return true;" name="AName" >
    [\code]

  • #3
    Regular Coder
    Join Date
    Jul 2002
    Location
    Western US
    Posts
    169
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I've see this behavior before. You can get around it by setting a flag to let you know that NS has infact shown the window. Depending on what you are trying to do, catch the onblur? or do you only want it to show the alert on a change? The following will work to correct the problem you are seeing, it might help, or might not depending on what/why you are trying to capture/do onblur...

    Code:
    var hasChange = false;
    function setChange(){
    	hasChange = true
    }
    
    function showAlert(msg){
    	if (hasChange){
    		alert(msg);
    		hasChange = false;
    	}
    }
    add that var, and functions, to the script on the space.html page
    then the input fields need to catch the change

    Code:
    <input type="text" onBlur="javascript:showAlert('Hifromsecondframe')" onChange="setChange()" name="AName" size="12">
    <input type="text" onBlur="javascript:showAlert('Hellofromsecondframe')" onChange="setChange()" name="AName" >

    That will keep NS from loopig on you. You could put the alert into a function like I have it there, and then set the flag after the alert pops up, but then you would need to reset the flag onfocus of another field, or track each field seperately. The onfocus might be more useful, but you will need to drop the alert, that is what is really causing your problem, it is taking focus and then returning it.

    ShriekForth

  • #4
    New Coder
    Join Date
    Jul 2002
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Problem with onBlur in frame in Netscape

    Hi,

    The problem with onChnage is that only if anything is changed in the textbox the alert will fire.

    If the user enters some wrong value and clicks outside ,alert will come but if again places the cursor in the same text box,and does not change anything then the alert will not fire.

    But for me the alert has to fire.Can u be little specific about the code.i just want to avoid the alert coming again and again it should come once and when the user does enter something wrong it has to fire again.

    What is the workaround

    Thanx
    Learner
    Last edited by learner; 08-20-2002 at 03:47 AM.

  • #5
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,068
    Thanks
    0
    Thanked 256 Times in 252 Posts
    you must be doing validation on onblur and onchange events. i think it's safer and better to validate once the submit button is clicked.

    <form onsumbit="return check(this)">

    then in your js code:

    function check(f){
    //checking here
    //return false if invalid value
    //return true if valid
    }
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #6
    New Coder
    Join Date
    Jul 2002
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Problem in onBlur

    Hi Glenn,

    U are absoultely right but without knowing then problems,this requirement from the client has been accepted and we to achieve the functionality

    Any help will be great.

    The alert is getting repeated if the mouse is clicked in the second frame and only once if the mouse is clicked in the first frame

    Thanx
    learner

  • #7
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,068
    Thanks
    0
    Thanked 256 Times in 252 Posts
    is this what you want?

    <script>
    function validate(el){
    val=el.value.trim();
    if (val==""){
    alert("Please enter something!");
    el.focus();//this is important so that it will trigger onblur event again.
    el.select();
    }
    else el.value=val;
    }

    String.prototype.trim=function(){
    var alt_255 = "%A0";
    string_temp = this;
    slen = string_temp.length;
    //trim left of string
    for (var i=0;i<slen;i++) {
    if ((this.charAt(i) == " ")||(escape(this.charAt(i)) == alt_255)) string_temp = this.substring(i+1,slen);
    else break;
    }
    string = string_temp;
    slen = string.length;
    //trim right of string
    for (var i=slen-1;i>=0;i--) {
    if ((string.charAt(i) == " ")||(escape(string.charAt(i)) == alt_255)) string_temp = string.substring(0,i);
    else break;
    }
    return string_temp;
    }
    </script>

    then in your textbox:
    <input name="text" onblur="validate(this)">

    i know there's a better trim function out there using regexp
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #8
    New Coder
    Join Date
    Jul 2002
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Problem with onBlur

    Hi Glenn,

    The alert please enter something comes in a loop when i dont enter anything in the textbox and click the mouse in the second frame.

    How to avoid it


    Thanks
    learner

  • #9
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,068
    Thanks
    0
    Thanked 256 Times in 252 Posts

    Re: Problem with onBlur

    i told you it's difficult to validate using onblur. my stand is still to validate on form onsubmit. you can explain to your client to use this method because it will annoy users if every onblur on a field, it will alert a msg.
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •