Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Form.submit() okay IE5.5 but not IE5.0

Status
Not open for further replies.

NewtUK

Programmer
Mar 13, 2001
21
0
0
GB
I am using the <form>.submit() function called from within another function in order to submit information to a servlet from a standard link using onClick(). This works in IE5.5+ but not 5.0! I have tried this on several machines that are running v5.0 to rule out a duff installation and have the same results.

All the information that I read about the function explains that it has been available since Javascript 1.0 so in theory, should work in IE3 let alone 5.

Ne1 have any ideas?

Cheers



Rich
 
are you using

<a href=&quot;javascript:functionCall();&quot;>click</a>

or

<a href=&quot;javascript:void(null);&quot; onclick=&quot;functionCall()&quot;>click</a>

Let us know! :) Gary Haran
 
I am using:

<a href='#' onClick=&quot;submitViaLink(document.frmPICKLIST,['OPTION','Certificate']);&quot;>Link Image</a>

The function that is being called is:

function submitViaLink(form,args)
{
for (i = 0 ; i < (args.length - 1) ; i += 2 )
{
if (args.length > 0)
{
form.action += ((i == 0 ? &quot;?&quot; : &quot;&&quot;) + args + &quot;=&quot; + args[i+1]);
}
}
form.submit();
}

This allows me to call the function with any parameters that need to be added to the action (namely, the function called in the servlet).

I've added alerts to see if there is anywhere in the function that might stop IE5.0 in its tracks, but it is only at the form.submit() point that it decides not to do anything.

Cheers



Rich
 
POST - changing to GET makes no odds.

Also tried using forms[0] instead of the name and still nothing happens. Don't even get a javascript error.
 
GOT IT!!!

I think it might be a bug in IE5.0. It was picking up the href='#' from the anchor tag and giving it priority over the onClick() event. Tried onMouseDown() instead which worked but not all the time (if I clicked too quick or in a space it didn't do anything), so changed it back to an onClick() event and removed the href attribute|value pair. Voilá, it now works (in 5.0 and 5.5 - just gotta try 6.0)!

Thankfully, I am using a rollover image as the link which means that at least the user will see that it is a link - if it was text (which I tested on), there would be no link highlighting, and the mouse pointer would remain as the text icon, so the user would not know that the option was there.

The other effect that this method has caused is that the mouse pointer no longer changes to a little hand, it just stays as a pointer, which I'm not too sure how to deal with (or even if I should bother).

I guess I need to make sure that this still works in NS6, too!!

Cheers for your assistance. Much appreciated :)



Rich
 
The most reliable way to accomplish this is to use...

<a href=&quot;submitViaLink(document.frmPICKLIST,['OPTION','Certificate']);&quot;>Link Image</a>

 
Mmmm, so it is!!

Must admit, I've never used Javascriptin the href attribute before. I'll do this when I get back to work tomorrow.

Cheers
 
Mmmm, so it is!!

Must admit, I've never used Javascript in the href attribute before - never realised it could be done (I've only been picking it up as I go along so have big gaps in my knowledge).

I'll do this when I get back to work tomorrow.

Cheers for your help
 
acero,

&quot;The most reliable way to accomplish this is to use...

<a href=&quot;submitViaLink(document.frmPICKLIST,['OPTION','Certificate']);&quot;>Link Image</a>&quot;

yes, but don't forget the javascript: pseudo-protocol, or you'll get a 404 page not found error.

<a href=&quot;javascript:submitViaLink(document.frmPICKLIST,['OPTION','Certificate']);&quot;>Link Image</a> ======================================

if (!succeed) try();
-jeff
 
Okay, I got the stuff to work based on all the suggestions, however, some changes have had to be made which means that I cannot call this function from the href attribute - I am now having to pass 'this' back to the function which means that the window gets passed back and not the anchor object; to get round this, I have to put the call back into the onClick() event.

I could get round it by calling a function that sets a variable to be passed, but this means that there is a risk of things being missed so I am trying to keep it all in one function so that there is just one call.

Any recommendations?

Cheers




Rich
 
Please ignore that last one - my brain's not working properly lately!!
 
I have been submitting forms like this in IE 5.0 using servicepack2. I dont know if it is the SP2 whcih is making the difference.
Try calling document.<formname>.submit(). Hope it works out.
 
Cheers, mate.

I realised I could just use href='#' since the function carries out the submission and it doesn't matter if the page jumps to the top since that is where the link is anyway.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top