Support » Fixing WordPress » I can’t my form to call a javascript function

  • Resolved FXDaddy



    I have been pulling my hair out trying to get this to work in WordPress. I am using the Atahualpa theme.

    My form takes reservation information from the user via a form and passes it to another page, which is a booking engine site.

    Everything works fine with the form when I create a standalone php or html page but as soon as I copy the form into WordPress, it doesn’t work. This all hinges on a javascript call that concatenates the date fields into a format that the booking engine can read, which is yyyymmdd. The actual input on the form is done through three separate dropdown menus.

    I use onSubmit=”combDep(), combRet()” to call the JS functions in the form tag. They are departure and return dates. My JS looks like this:

    <script type=”text/javascript”>
    function combDep()
    var dyear = document.forms[0].d_y.value;
    var dmonth = document.forms[0].d_m.value;
    var dday = document.forms[0].d_d.value;
    document.forms[0].DepartDate.value = dyear + dmonth + dday;
    function combRet()
    var ryear = document.forms[0].d_y2.value;
    var rmonth = document.forms[0].d_m2.value;
    var rday = document.forms[0].d_d2.value;
    document.forms[0].ReturnDate.value = ryear + rmonth + rday;

    I have tried all different combinations of plugins and calling the JS external file in the header, putting the JS in the form, etc and nothing seems to work. I installed the ‘AYB Javascript in Posts’ plugin and that is showing some promise because it can display simple JS code, but still can’t get the form to work. Any help would be greatly appreciated.

    The site is:


Viewing 5 replies - 1 through 5 (of 5 total)
  • esmi


    Forum Moderator

    Thanks esmi, but I have been through those pages extensively. I have tried them and they do not work. It looks like my onSubmit is not being called at the time of the form submission. I have turned off the visual editor. I have tried onSubmit at the form level and onClick at the submission button level. Any other ideas?




    Forum Moderator

    You’re trying to add this via the Visual Editor? Try creating a custom page template and adding it to the template file.

    This was a great idea and I will use it to get the formatting on my homepage to work, but it still doesn’t pass the information correctly. I tried putting it in the loop, out of the loop, etc. I also tried changing themes and it didn’t work. Here is what I pasted into the new template, maybe you can see something I’m missing. I really appreciate you helping me on this one, thanks!

    [Code moderated as per the Forum Rules. Please use the pastebin]

    OK, I finally got it! It was because the JS was looking for form[0] as the first form on the page. It works when I do a standalone page but when I put it into the WP template, form[0] is actually the search widget. I changed the JS to reference form[1] and it worked. I appreciate your help!!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘I can’t my form to call a javascript function’ is closed to new replies.