Jump to content

Archived

This topic is now archived and is closed to further replies.

alpine

result div inside form - IE + Opera problem

Recommended Posts

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.

Share this post


Link to post
Share on other sites
Can you post the js code. There may be an issue with the createRequestObject.

Share this post


Link to post
Share on other sites
sure, here it goes:
[code]
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 = '';
}
}
[/code]

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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 ###

[quote]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.[/quote]

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!

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.