PDA

View Full Version : DOM Form - everything works, other than submit()


foghorn87
03-05-2007, 02:39 PM
Hi Folks,


<script type="text/javascript">
function reloadform() {
document.account.submit()
//window.reload();
}
</script>

<form action="change_settings.php" method="post" id="account" name="account">

<select class='profile_settings_cntry' name='country' id='country' onChange="reloadform();">


The whole document is pretty long, but I wonder whether anyone can help me.

I have a countries list, with a regions list next to it, and if someone selects their country, through the magic of PHP and JS, it displays the appropriate regions list. The above is working on most of my pages, but not this one.

the onChange in the <select> tags is definitely working, as I tried changing the reloadform() function to alert('hello') and it worked. I then wondered whether the Form Document Object may not be creating, but alert(document.account.action) returned the correct form action. I then wondered whether for some reason, the document object was having problems with the actual functions, but document.account.reset() works!

Does anyone see a problem with this code, or know of any known issues that may stop it from working? The site stylist uses a lot of CSS, and I didn't know whether that may cause a conflict anywhere, anyhow?

Any help greatly received. Thanks in advance,

Tom

nikkiH
03-05-2007, 03:31 PM
Why do you think it is not submitting?
Perhaps it is, but something else is not working?

foghorn87
03-05-2007, 03:34 PM
Hi there,

When I submit the form data using the submit button, it works fine, information is saved and then displays on the page. I have just tried changing a form value, and then trying to submit the form by triggering the onchange thing.. but it definitely wasn't working.

What's more, I get a JS error, which I do not get with any of the other functions.

Cheers,

Tom

nikkiH
03-05-2007, 04:11 PM
What is the error message?

foghorn87
03-05-2007, 04:18 PM
Object doesn't support this property or method.

nikkiH
03-05-2007, 06:02 PM
alert(document.account)

please.
Also verify you have no other form fields accidentally also named account.

Try using this syntax instead.
document.forms["account"].submit();

If you still have trouble, please give a link or post the whole source so I can copy it and test.

foghorn87
03-05-2007, 08:31 PM
Hi there,

the alert() returns [object].

document.forms["account"].submit(); doesn't work.

I'll PM you the source... thanks again for your help with this!

Tom

foghorn87
03-05-2007, 09:10 PM
Also, just thought.. though I have checked for other elements with ID "account," the reset() function works.. which makes it even more odd that submit() doesn't. I was wondering whether there was anything about the form that would stop it from submitting, but I really can't see it.. it's a pretty standard form, I'd say.

Cheers,

Tom

foghorn87
03-05-2007, 09:21 PM
Thought I'd resolved it but I haven't.. hence post modified.

nikkiH
03-05-2007, 09:34 PM
Error: (firefox error console is SO much better than IE)

Error: document.account.submit is not a function
Source File: [snipped]
Line: 23

The reason:
Oops:
<input type="hidden" name="submit" value="submit">

You overrode submit when you named a form element that.

glenngv
03-05-2007, 09:40 PM
Run the page in Firefox and open the Javascript console to see more descriptive error message. Firefox error notification is much better than IE's.

Edit: Oopps, nikkiH beat me to it.

foghorn87
03-05-2007, 09:51 PM
Ah ha! Yes, I can see why that would cause confusion. Thanks once again for your help.... means I can actually finish the site tomorrow!

All the best,

Tom

nikkiH
03-05-2007, 10:04 PM
No problem!
Good luck.