Jump to content


Photo

result div inside form - IE + Opera problem


  • Please log in to reply
6 replies to this topic

#1 alpine

alpine
  • Members
  • PipPipPip
  • Advanced Member
  • 756 posts
  • LocationNorway

Posted 26 September 2006 - 08:28 PM

Hi,

If i put the responsetext id inside the form, IE and Opera wont display results, IE warns an unexpected runtime error on this.
With Firefox everything works fine, and Mozilla's debugger shows no errors either.

Problem: ----------------------------------------

<form>
<div id="msg"></div>
<input type="text" onchange="ajaxcheck('blah');">
<input type="submit">
</form>
--------------------------------------------------

OK :----------------------------------------------

<div id="msg"></div>
<form>
<input type="text" onchange="ajaxcheck('blah');">
<input type="submit">
</form>
---------------------------------------------------

Any solutions or explanations out there ??
Obviously i would in some cases prefer to echo the result within the form elements when i only use ajax to verify captcha image and nothing else.

#2 tomfmason

tomfmason
  • Staff Alumni
  • Advanced Member
  • 1,696 posts
  • Locationstealing your wifi

Posted 26 September 2006 - 08:44 PM

Can you post the js code. There may be an issue with the createRequestObject.


Traveling East in search of instruction, and West to propagate the knowledge I have had gained.

current projects: pokersource

My Blog | My Pastebin | PHP Validation class | Backtrack linux


#3 alpine

alpine
  • Members
  • PipPipPip
  • Advanced Member
  • 756 posts
  • LocationNorway

Posted 26 September 2006 - 10:10 PM

sure, here it goes:
function fieldctr(url, feltid, feltid2)
{
var AJAXObj = false;
var varsel = 'msg';
var verdi = document.getElementById(feltid).value;

if(feltid2)
{
var verdi2 = document.getElementById(feltid2).value;
}
else
{
var verdi2 = '0';
}
	
if (window.XMLHttpRequest)
{
try
{
AJAXObj = new XMLHttpRequest();
}
catch (e)
{
AJAXObj = false;
}
}
else if (window.ActiveXObject)
{
try
{
AJAXObj = new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
try
{
AJAXObj = new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e)
{
AJAXObj = false;
}
}
}
else
{
AJAXObj = false;
}
	
if (AJAXObj)
{
AJAXObj.open("get", encodeURI(url + ".php?val=" + verdi + "&val2=" + verdi2 + "&field=" + feltid + "&rand=" + (Math.random() * Date.parse(new Date()))), true);
		
AJAXObj.onreadystatechange = function ()
{
if (AJAXObj.readyState == 4)
{
document.getElementById(varsel).innerHTML = AJAXObj.responseText;

if(document.getElementById('err_' + feltid))
{
document.getElementById(feltid).style.border = '1px solid';
document.getElementById(feltid).style.borderColor = '#ff0000';
}
else
{
document.getElementById(feltid).style.border = '1px solid';
document.getElementById(feltid).style.borderColor = '#c0c0c0';
}
}
else
{
document.getElementById(varsel).innerHTML = '';
}
}
AJAXObj.send(null);
}
else
{
document.getElementById(varsel).innerHTML = '';
}
}


#4 ober

ober
  • Staff Alumni
  • Advanced Member
  • 5,337 posts
  • LocationEast Coast, USA

Posted 26 September 2006 - 10:27 PM

Can you give us a link to a live version so we can debug with our own JS debuggers?  I don't see anything explicitly wrong other than you're not using quotes around the names of the fileds in your getElementById calls.

Also, it's kind of a bad idea to create the object and handle the response all within the same function.  You can't reuse the object and you can't easily trap errors from the calling function as you have it.

Info: PHP Manual


#5 alpine

alpine
  • Members
  • PipPipPip
  • Advanced Member
  • 756 posts
  • LocationNorway

Posted 26 September 2006 - 10:59 PM

here is a re-created minimalistic live version, works a charm with result div above form. Here result div is placed below the captcha field.

it is onkeyup on the captcha:

### REMOVED: testpage eventually was removed from location ###

Also, it's kind of a bad idea to create the object and handle the response all within the same function.  You can't reuse the object and you can't easily trap errors from the calling function as you have it.


i am aware of that, but it feels easier for me to make a complete working script first and then split when its working - javascript is not my darkest belt *lol* and in lack of better tools i use mozilla's debugger for firefox, but this time i have only the lame error messages from IE. What a joke!

I wasn't aware of the quotes on elementbyid as i dont get any errors on it - but one learns!

#6 ober

ober
  • Staff Alumni
  • Advanced Member
  • 5,337 posts
  • LocationEast Coast, USA

Posted 27 September 2006 - 12:40 AM

I wish I could remember what the "runtime error" thing was caused by in a script of mine once.  Drove me insane for a few days.  I think it may have had something to do with how I was creating the object or something...

And that's pretty slick what you did.  So is the problem fixed or are you trying to do something more?

Info: PHP Manual


#7 alpine

alpine
  • Members
  • PipPipPip
  • Advanced Member
  • 756 posts
  • LocationNorway

Posted 27 September 2006 - 04:14 AM

Thanks ober

Well - problem is fixed and all forms running ok, i just outputted the text-result div above form and it's no problems.
Strange enough the images-div is no problem inside form elements.
Just very annoying when the cause of a small problem won't identify itself properly... and thats why i feel javascript as a harder language to learn than php.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users