Connecting Tech Pros Worldwide Forums | Help | Site Map

A simple function is not working. Must be something weird ... but what it is ???

Member
 
Join Date: May 2007
Posts: 67
#1: Nov 30 '07
I am having a very weird issue here, a simple form submit not working. Trying for several hours now ... must be something stupid ... help appreciated.

First, the html -
Expand|Select|Wrap|Line Numbers
  1. <form id="formFinale" method="post" action="noscript.php" enctype="application/x-www-form-urlencoded">
  2.  
  3.    <div class="myStyle">Votre nom ? <input type="text" size="36" name="ouchocolat" id="ouchocolat" value="" /></div>
  4.  
  5.    <div class="myStyle">J’ai lu et je suis d’accord avec les <a href="conditions.html"  onclick="this.target='_blank'">conditions générales de vente</a> : <input type="checkbox" name="agree" id="agree" /></div>
  6.  
  7.    <div class="rightContent right">
  8.       <div class="center"><input type="button" class="button" value="Paiement en ligne" onclick="ifagree('agree','formFinale','getForm.php?ph=3&action=bank');" /></div>
  9.  
  10.    </div>
  11.  
  12.    <div class="r">
  13.       <div class="center"><input type="button" class="button" value="Paiement par cheque" onclick="ifagree('agree','formFinale','getForm.php?ph=3&action=check');" /></div>
  14.  
  15.    </div>
  16. <div class="clearer"></div>
  17. </form>
  18.  
Then - the javascript.
Expand|Select|Wrap|Line Numbers
  1. function multiSubmit(formId,url) {
  2.     document.getElementById(formId).action=url;
  3. }
  4.  
  5. function ifagree(id,formId,url) {
  6.     if (document.getElementById(id).checked == false) {
  7.         alert('Veuillez accepter les condition général de vente.');
  8.         return false;
  9.     } else {
  10.         if(url) {
  11.             return multiSubmit(formId,url);
  12.         } else {
  13.             return true;
  14.         }
  15.     }
  16. }
  17.  
It seems to be getting executed in case I change the line from document.getElementById(formId).action=url; to alert(document.getElementById(formId).action);

I can see that I am getting the right action in the alert. However, as it stands now, it's simply not working. :(:(:(

What's happening when I tell that it's not working? Well, problem is nothing really is working. No error icon in IE, no error in FF error console, nothing moves as I click on either of these buttons !

Joining the two functions to one doesn't change things either ...

Expand|Select|Wrap|Line Numbers
  1. function ifagree(id,formId,url) {
  2.     if (document.getElementById(id).checked == false) {
  3.         alert('Veuillez accepter les condition général de vente.');
  4.         return false;
  5.     } else {
  6.         if(url) {
  7.             document.getElementById(formId).action=url;
  8.         } else {
  9.             return true;
  10.         }
  11.     }
  12. }
  13.  
Thanks for having a look.
Regards.

Dasty's Avatar
Expert
 
Join Date: Nov 2007
Location: Slovakia
Posts: 101
#2: Nov 30 '07

re: A simple function is not working. Must be something weird ... but what it is ???


Setting action property does not submit form. You have to submit it somewhere.

Expand|Select|Wrap|Line Numbers
  1. document.getElementById(formId).submit();
Member
 
Join Date: May 2007
Posts: 67
#3: Dec 1 '07

re: A simple function is not working. Must be something weird ... but what it is ???


thanks Dasty, you are a genious :)
Reply


Similar JavaScript / Ajax / DHTML bytes