Form button just stopped working

Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Reply

Join Date: Jun 2009
Posts: 19
Reputation: drugoholic is an unknown quantity at this point 
Solved Threads: 0
drugoholic drugoholic is offline Offline
Newbie Poster

Form button just stopped working

 
0
  #1
Jul 9th, 2009
Hello,

I'm having a problem understanding why would a form I built before would stop working now. Basically I have some javascript functions that are being called in a reservation form with 2 buttons.

This is the JS code:
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. var bgMemory; // save color information
  2. var fgMemory;
  3. var statusinfo = false;
  4. function mOver(cell, id, statustxt)
  5. {
  6.  
  7. cell.style.cursor = 'hand';
  8. cell.style.backgroundColor='#e6e6e6';
  9. if (typeof document.getElementById(id + "cc") == "object")
  10. {
  11. Elem = document.getElementById(id + "cc");
  12. bgMemory = Elem.style.backgroundColor;
  13. Elem.style.backgroundColor='#e6e6e6';
  14. }
  15. if (typeof document.getElementById(id + "l") == "object")
  16. {
  17. Elem = document.getElementById(id + "l");
  18. fgMemory = Elem.style.color;
  19. Elem.style.color='#3D6484';
  20. }
  21. window.status=statustxt;
  22. statusinfo = true;
  23. return true;
  24. }
  25. function mOut(cell, id)
  26. {
  27.  
  28. cell.style.cursor = 'hand';
  29. cell.style.backgroundColor='';
  30. window.status="";
  31. if (typeof document.getElementById(id) == "object")
  32. {
  33. Elem = document.getElementById(id + "cc");
  34. Elem.style.backgroundColor = bgMemory;
  35. }
  36. if (typeof document.getElementById(id + "l") == "object")
  37. {
  38. Elem = document.getElementById(id + "l");
  39. Elem.style.color = fgMemory;
  40. }
  41. window.status='';
  42. statusinfo = false;
  43. return true;
  44. }
  45. function mClick(cell)
  46. {
  47. if(event.srcElement.tagName=='TD')
  48. {
  49. cell.children.tags('A')[0].click();
  50. }
  51. }
  52. </script>
  53. <script type = "text/javascript">
  54. var xMonths = new Array( 'jan', 'feb', 'mar', 'apr', 'may', 'jun', 'jul', 'aug', 'sep', 'oct', 'nov', 'dec' );
  55.  
  56. function getListValue( option_object ) {
  57. return option_object.options[option_object.selectedIndex].value;
  58. }
  59.  
  60. function setListValue( option_object, value ) { option_object.selectedIndex = value; }
  61.  
  62. function addDays(myDate,days) {
  63. return new Date(myDate.getTime() + days*24*60*60*1000);
  64. }
  65. function init()
  66. {
  67. xToday = new Date();
  68. yToday = addDays(new Date(),3);
  69.  
  70. xMonth = xToday.getMonth();
  71. xDay = xToday.getDate()-1;
  72. xYear = xToday.getYear()-2005; if (xYear < 2005) xYear=0;
  73.  
  74. yMonth = yToday.getMonth();
  75. yDay = yToday.getDate()-1;
  76. yYear = yToday.getYear()-2005; if (yYear < 2005) yYear=0;
  77. xF = document.forms['quickbooking'];
  78. setListValue( xF.ETAHour, 9 )
  79. setListValue( xF.ETAMonth, xMonth )
  80. setListValue( xF.ETADay, xDay )
  81. setListValue( xF.ETAYear, xYear )
  82. setListValue( xF.ETTHour, 9 )
  83. setListValue( xF.ETTMonth, yMonth )
  84. setListValue( xF.ETTDay, yDay )
  85. setListValue( xF.ETTYear, yYear )
  86. }
  87.  
  88.  
  89. function openhelp( hlpString )
  90. {
  91. hlpWin = window.open( hlpString , 'Help', 'width=395,height=345,resizable=yes,scrollbars=yes,status=yes')
  92. hlpWin.focus();
  93. }
  94.  
  95. function doContinue( )
  96. {
  97. xF = document.forms['quickbooking'];
  98. xETADay = getListValue( xF.ETADay );
  99. xETAMonth = getListValue( xF.ETAMonth );
  100. xETAYear = getListValue( xF.ETAYear );
  101. xETAHour = getListValue( xF.ETAHour );
  102. xETAMinute = getListValue( xF.ETAMinute );
  103. xETA = xETADay + xMonths[ parseInt( xETAMonth )-1 ] + xETAYear.substr(2,2) + '/' + xETAHour + xETAMinute;xETTDay = getListValue( xF.ETTDay );
  104. xETTMonth = getListValue( xF.ETTMonth );
  105. xETTYear = getListValue( xF.ETTYear );
  106. xETTHour = getListValue( xF.ETTHour );
  107. xETTMinute = getListValue( xF.ETTMinute );
  108. xETT = xETTDay + xMonths[ parseInt( xETTMonth )-1 ] + xETTYear.substr(2,2) + '/' + xETTHour + xETTMinute;
  109. xWizardNumber = xF.wizard_number.value;
  110. xName = xF.surname.value ;
  111. xRL_Country = xF.Country.value ;
  112. xParams = '&CTR=' + xCountry +'&Country=' + xCountry + '&ETA=' + xETA + '&ETT=' + xETT+ '&CNAM=' + xName + '&WIZ=' + xWizardNumber+'&SOR=0038780x';
  113. url = 'http://book.rent-at-avis.com/avisonline/ibe.nsf/PrefillX?OpenAgent&ResStep=ReservationStep1&IBEOwner=EU&LNG=GB' + xParams;location.href = url;
  114. }
  115. window.onload = init;

And this is the 2 buttons of the form:
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <FORM name=quickbooking action=javascript:doContinue(); method=post>
  2. <input class="formButton" id="more_options" onclick="doContinue();" type="button" value="More options" name="more_options" />
  3. <input class="formButton" id="continue" onclick="doContinue();" type="button" value="Continue" name="continue" selected="selected" />

The "More Options" button is working fine but when I enter my email and click on "Continue" it doesn't do anything, if I leave the email field blank and click continue it works but poping the alertbox... Help would be really appreciated, thank you.

I just realized that if you goto the page http://www.avis.com.lb/ and you view the page's source, you'll notice in the javascript that there are 2 email validation functions and none of them is present in the actual file code (reservation-form.html)... I don't know where are they coming from.
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 49
Reputation: sysel is an unknown quantity at this point 
Solved Threads: 3
sysel sysel is offline Offline
Light Poster

Re: Form button just stopped working

 
0
  #2
Jul 9th, 2009
Sorry, but your scripts do exactly what you wrote. There is no submit() command nor SUBMIT button, hence no reason to do the <FORM action="....">
Try to write less decorative but more functional test page with simple form and either submit() methde either SUBMIT button. :-)
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 19
Reputation: drugoholic is an unknown quantity at this point 
Solved Threads: 0
drugoholic drugoholic is offline Offline
Newbie Poster

Re: Form button just stopped working

 
0
  #3
Jul 9th, 2009
Sorry, I might have been misleading in my previous posts, but I figured out what the real problem is.

URL: http://www.avis.com.lb (check the form on the main page)

The problem is with the email field validation, I removed it and the form seems to be working fine.

My question is, I really need to have the email validation working, so what's the best way to do this?
Keep the 2 functions doContinue() and validemail() seperated and then call them with onclick="return docontinue() && validemail();" or merge the 2 functions and call them with 1 value onclick="docontinue()".

However, I tried both ways and none of them worked with coz I would really appreciate your help in here...
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 49
Reputation: sysel is an unknown quantity at this point 
Solved Threads: 3
sysel sysel is offline Offline
Light Poster

Re: Form button just stopped working

 
0
  #4
Jul 9th, 2009
Yes I must stay on my previous response
- either finish the doContinue() function with somthing like: this.form.submit()
- either use the type="SUBMIT" instead of type="BUTTON"

And cut off the lines which disables the error warning in ought to debbug easy your code.

I really saw the fullcoloured AVIS page. :-)
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 19
Reputation: drugoholic is an unknown quantity at this point 
Solved Threads: 0
drugoholic drugoholic is offline Offline
Newbie Poster

Re: Form button just stopped working

 
0
  #5
Jul 9th, 2009
- either finish the doContinue() function with somthing like: this.form.submit()
That didn't work.

- either use the type="SUBMIT" instead of type="BUTTON"
This also didn't work, I change the type to SUBMIT and I added an ONCLICK as well: onclick="return validemail() && doContinue();"

And still it wouldn't work.... It keeps asking me to enter an email whether I enter one or leave it blank.

And thanks alot for your help.
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 49
Reputation: sysel is an unknown quantity at this point 
Solved Threads: 3
sysel sysel is offline Offline
Light Poster

Re: Form button just stopped working

 
0
  #6
Jul 9th, 2009
Well, then the RegExp must be wrong. Try it separately. There is plenty of email validation examples. When I put this into my Kate text editor it does not find any email address. Try to delete the last $ (dollar sign)
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 19
Reputation: drugoholic is an unknown quantity at this point 
Solved Threads: 0
drugoholic drugoholic is offline Offline
Newbie Poster

Re: Form button just stopped working

 
0
  #7
Jul 9th, 2009
Originally Posted by sysel View Post
Well, then the RegExp must be wrong. Try it separately. There is plenty of email validation examples. When I put this into my Kate text editor it does not find any email address. Try to delete the last $ (dollar sign)
What last dollar sign?

Just a question, let's say I have 2 functions: docontinue() and emailvalidation() and I'm trying to call them with the onclick. So would this be correct:

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. onclick="return validemail() && doContinue();"
Or this
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. onsubmit = "return (validateEmail() && doContinue())"
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 49
Reputation: sysel is an unknown quantity at this point 
Solved Threads: 3
sysel sysel is offline Offline
Light Poster

Re: Form button just stopped working

 
0
  #8
Jul 9th, 2009
In the validateEmail() function there is a RegExp definition /^([a-z0-9])([\w\.\-\+])+([a-z0-9])\@(([\w\-]?)+\.)+([a-z]{2,4})$/i
which, I suppose, does not work correctly. It could be very useful if you test this RegExp or the whole function validateEmail() separately.

The $ in Regular Expression means the end of text row but may be not good in text input.

It could be a good idea to write a small test page for testing each functionality of such complex page. Your page for example allows uset to fill in the date of Februar 31 ! this must be also validate or disallowed.
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 49
Reputation: sysel is an unknown quantity at this point 
Solved Threads: 3
sysel sysel is offline Offline
Light Poster

Re: Form button just stopped working

 
0
  #9
Jul 9th, 2009
Sorry, I did not note the location.href command, which is used instead of submit(). It seems to me to be more complicated than by using the standard methods. Also the methode="post" is better for transfer of data to server. The doContinue() is doing that what normal form.submit() does itself.

I can also advice to do the validation of email and other user input immediately after the user finished it. So e.g.: <input name="email" onBlur="this.value=validateEmail(this.value)"> and the validation function can check and repair the user input, or <select name="day" onChange="validateDate(this)">

It is very dangerous to simply copy/paste some code you do not know what and how exactly work.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the JavaScript / DHTML / AJAX Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC