Connecting Tech Pros Worldwide Forums | Help | Site Map

Form Submit Using java Script Not working in IE

Newbie
 
Join Date: Jan 2007
Posts: 7
#1: Aug 30 '07
Hi
i have a requirement to pass the parameters say account No to a javaScript when the user clicks a link , The form action will also be set in JavaScript, and form is submitted in JavaScript,Its working fine in firefox browser, but its not working in IE , Is there any other way other than Calling the
JavaScript Function from <a:href =javascript:viewAccountDetail>, This solution does not suit for me since it shows the account No in Status Bar.Thanks in Advance


Expand|Select|Wrap|Line Numbers
  1.  function viewAccountDetail(friendlyID,finCompID)
  2.     {
  3.     document.getElementById('accountNo').value=accountNo;
  4.     document.forms['accounts'].action=friendlyID;
  5.         document.forms['accounts'].method="post";
  6.     document.forms['accounts'].submit();
  7.         return true;
  8.     }
  9.  
[HTML]<form id="accounts" name="accounts" method="post">
<input type="hidden" id="accountNo" name="accountNo" />
</form>

<a href="javascript:void(0);" onClick="return viewAccountDetail('${account.URL}','${account.acco untNo});">Account Desc</a>[/HTML]

iam_clint's Avatar
Forum Leader
 
Join Date: Jul 2006
Location: Oklahoma
Posts: 1,076
#2: Aug 30 '07

re: Form Submit Using java Script Not working in IE


i would do something like this.
Expand|Select|Wrap|Line Numbers
  1. function viewAccountDetail(friendlyID,finCompID)    {
  2.     document.getElementById('accountNo').value=account  No;
  3.     form = document.getElementById("accounts");
  4.     form.setAttribute("action", friendlyID);
  5.     form.setAttribute("method", "POST");
  6.     form.submit();
  7.     return true;
  8.  }
  9.  
Expert
 
Join Date: Aug 2007
Location: UK
Posts: 153
#3: Aug 30 '07

re: Form Submit Using java Script Not working in IE


Hi Jad,

Welcome to TSDN,

I think the problem is that you were returning true from the function, returning false would prevent the link from being followed, I have also changed the funciton slightly so that the getElementById is not required. The following code works:
Expand|Select|Wrap|Line Numbers
  1. function viewAccountDetail(friendlyID,finCompID){
  2.     document.accounts.accountNo.value=finCompID;
  3.     document.forms['accounts'].action=friendlyID;
  4.     document.forms['accounts'].method="post";
  5.     document.forms['accounts'].submit();
  6.     return false;
  7. }
  8.  
[HTML]
<body>
<form id="accounts" name="accounts" method="post">
<input type="hidden" id="accountNo" name="accountNo" />
</form>
<a href="http://www.google.com" onClick="return viewAccountDetail('#','123456');">Account Desc</a>
</body>
[/HTML]

I also changed the value that was being assigned to the hidden input from accountNo to finCompID which was being passed in but not used as the accountNo variable did not seem to be declared in your code. I used dummy variables in the call to the function and changed the href of the link to google so that I could confirm it wasn't being followed.
iam_clint's Avatar
Forum Leader
 
Join Date: Jul 2006
Location: Oklahoma
Posts: 1,076
#4: Aug 30 '07

re: Form Submit Using java Script Not working in IE


i would rather use getElementById myself document.forms.accounts would work also.

would also use setattribute.
Newbie
 
Join Date: Jan 2007
Posts: 7
#5: Aug 31 '07

re: Form Submit Using java Script Not working in IE


Thanks iam_clint,phvfl.It works fine
and a special thanks to gits for making my post presentable
gits's Avatar
Moderator
 
Join Date: May 2007
Location: Munich, Germany
Posts: 4,134
#6: Aug 31 '07

re: Form Submit Using java Script Not working in IE


hi ...

no problem ... simply remember to use the code-tags next time for yourself ;) ...

kind regards
Reply