Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
form does not submit in IE with click()
Old 03-03-2008, 11:18 AM form does not submit in IE with click()
Novice Talker

Posts: 6
Name: Glen
Trades: 0
Hi,

I have a form that I'm using as a top level menu for a web-enabled application. The form allows the user to select from a number of different computer systems by clicking a styled html anchor tag with an onclick event. The onclick calls javascript to set the value of a hidden (via css) submit input and then submit the form using the input's .click() method. This has worked for me in the past, and in this case, works just fine in Firefox, but not in IE 6.

Here is what I have verified:
1) When I click one of the anchor tags, the loadResource function fires.
2) When the .click() method is called, the click event on the submit input fires.
3) When the .click() method of the submit input fires, the PHP on the server does NOT get called.
4) If I unhide the submit input and click it manually, everything works.

At this point, I'm completely stumped. I hope someone can help.

Here's the form:

HTML Code:
 <form name="systems" id="systems" action="outage.php" method="post">
  <a id="Jade"
    onclick="loadResource(event);"
    href="javascript:{}">Jade</a>
  <a id="Sapphire"
    onclick="loadResource(event);"
    href="javascript:{}">Sapphire</a>
  <input id="system"
    name="system"
    value=""
    class="sysBtn"
    type="submit" />
  <input type="hidden" 
    value="false" 
    name="write"/>
</form>
Here is the loadResource javascript function:
Code:
function loadResource(e) {
  e = (typeof(event) == 'undefined') ? e : event;
  var elem = $(e.target || e.srcElement);
  var system = document.getElementById('system');
  system.value = elem.id;
  system.click();
}
On the server side, this is being handled by PHP. As a sanity check, I inserted the following code to show me what is actually being passed into the _POST array...
Code:
printf("<div>");
foreach($_POST as $key => $value){
  printf("%s = %s<br />\n",$key, $value);
}
printf("</div>");
This code never gets called when the page is loaded in IE. It doesn't even generate the <div> tags.
browni is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 03-03-2008, 11:25 AM Re: form does not submit in IE with click()
ADAM Web Design's Avatar
Canadastaninianite

Posts: 5,938
Name: Adam for web page design, not program
Location: Toronto, Ontario, Canada
Trades: 0
Instead of relying on "system"'s click method, why not rely on the form's submit method itself? That's usually a lot more stable.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
(my blog)


Please login or register to view this content. Registration is FREE
(with proof)
ADAM Web Design is offline
Reply With Quote
View Public Profile Visit ADAM Web Design's homepage!
 
Old 03-03-2008, 11:33 AM Re: form does not submit in IE with click()
Novice Talker

Posts: 6
Name: Glen
Trades: 0
I have tried the following:

var system = document.getElementById('system');
var systemForm = document.getElementById('systems');
system.value = elem.id;
systems.submit();

The result was that it broke in Firefox and made no difference in IE.
browni is offline
Reply With Quote
View Public Profile
 
Old 03-03-2008, 11:38 AM Re: form does not submit in IE with click()
ADAM Web Design's Avatar
Canadastaninianite

Posts: 5,938
Name: Adam for web page design, not program
Location: Toronto, Ontario, Canada
Trades: 0
What's the IE error that you get? That should work.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
(my blog)


Please login or register to view this content. Registration is FREE
(with proof)
ADAM Web Design is offline
Reply With Quote
View Public Profile Visit ADAM Web Design's homepage!
 
Old 03-03-2008, 11:43 AM Re: form does not submit in IE with click()
Novice Talker

Posts: 6
Name: Glen
Trades: 0
No error at all. Nothing. nada. It just does nothing.
browni is offline
Reply With Quote
View Public Profile
 
Old 03-03-2008, 12:30 PM Re: form does not submit in IE with click()
Novice Talker

Posts: 6
Name: Glen
Trades: 0
I added an onsubmit event to the form tag...

onsubmit="alert('hi');"

just to see if the form submit event is firing. It dutifully alerted "hi", but from all appearances, did not negotiate with the server at all.
browni is offline
Reply With Quote
View Public Profile
 
Old 03-03-2008, 12:52 PM Re: form does not submit in IE with click()
ADAM Web Design's Avatar
Canadastaninianite

Posts: 5,938
Name: Adam for web page design, not program
Location: Toronto, Ontario, Canada
Trades: 0
Try adding "return true;" to the onsubmit handler just to see if it actually submits anything. That's about all I can think of without seeing the page.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
(my blog)


Please login or register to view this content. Registration is FREE
(with proof)
ADAM Web Design is offline
Reply With Quote
View Public Profile Visit ADAM Web Design's homepage!
 
Old 03-03-2008, 02:58 PM Re: form does not submit in IE with click()
Novice Talker

Posts: 6
Name: Glen
Trades: 0
I tried that too. I added onsubmit="return true;" to the form tag. No change.

As far as I can tell, IE is not negotiating with the server at all.
browni is offline
Reply With Quote
View Public Profile
 
Old 03-03-2008, 03:18 PM Re: form does not submit in IE with click()
Novice Talker

Posts: 6
Name: Glen
Trades: 0
I found a workaround.

I'm not sure what makes the difference here, but at least this works....

Instead of this:
HTML Code:
<a id="Jade"
    onclick="loadResource(event);"
    href="javascript:{}">Jade</a>
I did this:
HTML Code:
<a id="Jade"
 href="javascript:$('system').value='Jade';$('system').click()">Jade</a>
... and everything is happy. (ugly, but happy)
browni is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to form does not submit in IE with click()
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.33463 seconds with 12 queries