Jump to content

result div inside form - IE + Opera problem


alpine

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.
Link to comment
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]
Link to comment
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.
Link to comment
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!
Link to comment
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?
Link to comment
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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.