JavaScript value from pop-up window

Posted on 2012-08-17
Last Modified: 2012-08-20
This seems a bit trivial but it is not working for me.

I have a form with a text field and an icon next to it that, when clicked, launches a pop-up window for selecting a date from a calendar.  The calendar package is the Tigra Calendar javascript module.

After selecting a date the text field is populated with the date in yyyy-mm-dd format.

In some other javascript code, I would like to check that a date is chosen.  I simply want to check if the field has a value or not.  But for some reason, when I check this field in the code, it does not find the element value.  I set an alert(scan_date) but no alerts pop-up after choosing the date.  If I manually type in the date value in the field, it does get this value and the alert pops up.

For getting the value, I use this line:

var scan_date = document.getElementById("scan_date").value;

Open in new window

The PHP code is:
<input type=text id="scan_date" name="scan_date" value="<?php echo $scan_date;?>" class=input maxlength=10> <?php echo $flag;?>
<a href="javascript:cal1.popup();"><img src="img/cal.gif" width="16" height="16" border="0" alt="Click here to pick the date"></a>

Open in new window

After the form closing tag I have:

var cal1 = new calendar1(document.forms['addnew'].elements['scan_date']);
cal1.year_scroll = true;
cal1.time_comp = false;

Open in new window

I figured that's all the information that I need to put here for the experts to figure this out.  It seems that it should be pretty straightforward.
Question by:mock5c
    LVL 75

    Expert Comment

    by:Michel Plungjan
    The calendar likely renames the field. Look in the documentation and add the code to something like onselect

    Author Comment

    When I select the value from the popup, the field is populated with the date.  This field is "scan_date".  I was hoping that since the field was populated via selecting from popup, this would trigger an onChange event and then the alert dialog would display the date that was selected.  This is not what happens.  This field does not seem to register an onchange event unless I were to manually enter the date in.

    I just noticed that if I select a date from the popup and the scan_date field is populated, and then go to a different field with an onchange event and enter a value manually, the alert dialog for displaying the date will show the date I  previously just chose in the popup.  How can I make this so that this happens immediately after the date is chosen from the popup?
    LVL 75

    Accepted Solution

    Onchange is not triggered from script unless you trigger it specifically
    As I said: go to the documentation of Tigra or their forum

    Author Closing Comment

    I discovered that I had an ancient version of Tigra calendar.  So after updating and reading the forum link, everything has been resolved.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
    These days socially coordinated efforts have turned into a critical requirement for enterprises.
    The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
    The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

    730 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now