Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

PHP Post not passing Variable when using JS

  • 12-04-2011 12:38PM
    #1
    Registered Users, Registered Users 2 Posts: 378 ✭✭


    Hi guys

    As part of my form, a user is allowed to pick a "closing date" using a JS calender

    Here is the JS Script:

    <script type="text/javascript" src="js/jsDatePick.min.1.3.js"></script>
    <script type="text/javascript">
    window.onload = function(){
    new JsDatePick({
    useMode:2,
    target:"closingdate",
    dateFormat:"%d-%m-%Y"
    });
    };
    </script>


    and the form input:

    <input type="text" name="closingdate" style="width: 260px" value ="'.$closingdate.'" id="closingdate"></input>


    When I select my date, and post the date, the variable is not carried accross

    If I remove the id="closindate", and manually enter something into the text box, it works fine, that way I know its the JS that is causing the variable not to POST

    Any help at all would be greatly appreciated

    Many thanks in advance


Comments

  • Registered Users, Registered Users 2 Posts: 9,579 ✭✭✭Webmonkey


    [php]<input type="text" name="closingdate" style="width: 260px" value ="'.$closingdate.'" id="closingdate"></input>[/php]

    Can you give more info on this. Is this printed as a PHP string? - otherwise you won't get the value of $closingdata as it's not interpreted by PHP.


  • Registered Users, Registered Users 2 Posts: 378 ✭✭bob2oo7


    Webmonkey wrote: »
    [php]<input type="text" name="closingdate" style="width: 260px" value ="'.$closingdate.'" id="closingdate"></input>[/php]Can you give more info on this. Is this printed as a PHP string? - otherwise you won't get the value of $closingdata as it's not interpreted by PHP.

    Hi Webmonkey

    This is indeed printed and it variable works perfectly fine if I dont use JS, all other variables within the form are passed except this one


  • Registered Users, Registered Users 2 Posts: 9,579 ✭✭✭Webmonkey


    What happens if you don't load the date thing and leave in the id="closingdate" and manually enter it. Does that work?


  • Registered Users, Registered Users 2 Posts: 378 ✭✭bob2oo7


    Webmonkey wrote: »
    What happens if you don't load the date thing and leave in the id="closingdate" and manually enter it. Does that work?

    It does indeed, works perfectly fine


  • Closed Accounts Posts: 27,856 ✭✭✭✭Dave!


    <input type="text" name="closingdate" style="width: 260px" value ="'.$closingdate.'" id="closingdate"></input>

    Doesn't the PHP variable need to be enclosed in PHP tags? (<?php ?>)

    Maybe I'm mistaken...


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 378 ✭✭bob2oo7


    Hi Dave

    You are correct, I didnt post all my code on here but the entire page is in closed in PHP tags


  • Registered Users, Registered Users 2 Posts: 668 ✭✭✭Freddio


    Are you looking at it in IE - if so do you have javascript errors prior to what you quoted? also is the date format of the javascript compatible with any sql behind the form?


  • Registered Users, Registered Users 2 Posts: 9,579 ✭✭✭Webmonkey


    Check the error console for errors in your browser. Surely it will show something. I think I used that date picker thing before without any problems on a site.


  • Moderators, Society & Culture Moderators Posts: 9,688 Mod ✭✭✭✭stevenmu


    If you pick the date and not submit the form, can you see the date in the field ?


  • Registered Users, Registered Users 2 Posts: 378 ✭✭bob2oo7


    Thanks for the replies guys

    I got this sorted

    I needed to put the JS code in the head of the page that is calling the function, I only had it in the page that the function is on (if that makes sense)

    All sorted now and working

    Appreciate the help and guidance


  • Advertisement
Advertisement