...

View Full Version : Problem with onBlur in frame in Netscape- Veryvery urgent



learner
08-19-2002, 07:23 PM
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

Roy Sinclair
08-19-2002, 09:41 PM
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]

ShriekForth
08-19-2002, 09:50 PM
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...



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



<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

learner
08-20-2002, 04:43 AM
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

glenngv
08-20-2002, 04:50 AM
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
}

learner
08-20-2002, 04:55 AM
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

glenngv
08-21-2002, 10:47 AM
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

learner
08-24-2002, 10:56 AM
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

glenngv
08-26-2002, 06:53 AM
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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum