Solved

How can I generate a value from a drop down and pass it to a text box

Posted on 2007-11-19
2
130 Views
Last Modified: 2010-04-09
Hi,

Below is some html which has a popup calendar to select a date and time format and assign it to a text box.

How can I also generate a date time value using the predefinded values from the drop down and assign that value to the same text box.

I must be in this format : dd-mm-yyyy hh:mm:ss.

<form id="form1" name="form1" method="post" action="savenote.asp">

<table width="920" border="0">

  <tr>

    <td colspan="3">Add Customer Call Note </td>

    </tr>

  <tr>

    <td width="339">Call Back Status </td>

    <td width="414">Call Note 

      <input name="frmCURN" type="hidden" id="frmCURN" value="329376" />

      <input name="frmSID" type="hidden" id="frmSID" value="1" /></td>

    <td width="153">Call Back Date / Time </td>

  </tr>

  <tr>

    <td><select name="frmCallBack" size="1" id="frmCallBack">

                  <option value="0">-- select --

                    

                  </option>

                  <option value="1">Not In | 

                  </option>

                  <option value="2">Call Back Later | 

                  </option>

                  <option value="3">Call Back Tomorrow | DateAdd("d",1,Date)

                  </option>

                  <option value="4">Call Back Next Week | DateAdd("d",7,Date)

                  </option>

                  <option value="5">Call Back In A Month | DateAdd("m",1,Date)

                  </option>

                  <option value="6">Call Back In Two Months | DateAdd("m",2,Date)

                  </option>

                  <option value="7">Dont Call Me Again | 

                  </option>

                </select>    </td>

    <td><input name="frmCallNote" type="text" id="frmCallNote" size="60" maxlength="60" /></td>

    <td><input name="frmCallBackDate" type="Text" id="frmCallBackDate" value="" size="16" readonly="">

	  <a href="javascript:cal3.popup();"><img src="img/cal.gif" width="16" height="16" border="0" alt="Click Here to Pick up the date"></a></td>

  </tr>

  <tr>

    <td colspan="3"><hr size="1" /></td>

    </tr>

  <tr>

    <td colspan="3"><table width="100%" border="0">

      <tr>

        <td width="83%">Customer not in when you called, set call back status to Not In, set a time for retry in Call Back Date / Time.</td>

        <td width="17%" align="right"><input type="submit" name="Submit" value="Save" /></td>

      </tr>

    </table></td>

    </tr>

  <tr>

    <td colspan="3">	</td>

  </tr>

</table>

</form>
 

			<script language="JavaScript">

			<!-- // create calendar object(s) just after form tag closed

				 // specify form element as the only parameter (document.forms['formname'].elements['inputname']);

				 // note: you can have as many calendar objects as you need for your application

				var cal3 = new calendar1(document.forms['form1'].elements['frmCallBackDate']);

				cal3.year_scroll = true;

				cal3.time_comp = true;

			//-->

			</script>

Open in new window

0
Comment
Question by:BenthamLtd
2 Comments
 
LVL 4

Accepted Solution

by:
rallsaldo earned 500 total points
ID: 20315941
Hi,

Add in the following JavaScript function:

function newDate(dateOption)
 {
  var myDate=new Date();
  var myVal;

  switch (dateOption)
   {
   //Tomorrow
   case 3:
    myDate.setDate(myDate.getDate()+1);
    break;

   //Next Week
   case 4:
    myDate.setDate(myDate.getDate()+7);
    break;

   //In one month
   case 5:
      myDate.setDate(myDate.getDate()+30);
    break;

   //In two months
   case 6:
    myDate.setDate(myDate.getDate()+60);
    break;

   default:
    myVal = "none";
    break;
   }

   if (myVal=="none")
    {
     myVal ="";
    }
   else
    {
         //dd-mm-yyyy hh:mm:ss
         //broken down for simplicity
         var myDay = myDate.getDate();
         var myMonth = myDate.getMonth() + 1;
         var myYear = myDate.getYear();

         var myHour = myDate.getHours();
         var myMin = myDate.getMinutes();
         var mySecond = myDate.getSeconds();

         myVal = myDay + "-" + myMonth + "-" + myYear + " " + myHour + ":" + myMin + ":" + mySecond;
      }
   document.getElementById("frmCallNote").value = myVal;

 }

and add in to the Select object a call to the JavaScript function:
<select name="frmCallBack" size="1" id="frmCallBack" onchange="newDate(this.selectedIndex)">

The options are very basic, I have only added 30 days (for 1 month) and 60 days (for 2 months) but this should start you off...

Hope that helps,
R
0
 

Author Comment

by:BenthamLtd
ID: 20318643
Thanks rallsaldo,

That was spot on.

I have made part of the javascript routine dynamic, and it works a treat.

Many thanks
<script language="JavaScript">

function newDate(dateOption)

 {

  var myDate=new Date();

  var myVal;
 

  switch (dateOption)

   {

   <%do until rsCallBackStatusJava.eof%>   

   //<%=rsCallBackStatusJava("CallBackStatus")%>

   case <%=rsCallBackStatusJava("CallBackID")%>:

    <%=rsCallBackStatusJava("DateCode")%>

    break;

<%rsCallBackStatusJava.movenext

		loop%>

  
 

   default:

    myVal = "none";

    break;

   }
 

   if (myVal=="none")

    {

     myVal ="";

    }

   else

    {

         //dd-mm-yyyy hh:mm:ss

         //broken down for simplicity

         var myDay = myDate.getDate();

         var myMonth = myDate.getMonth() + 1;

         var myYear = myDate.getYear();
 

         var myHour = myDate.getHours();

         var myMin = myDate.getMinutes();

         var mySecond = myDate.getSeconds();
 

         myVal = myDay + "-" + myMonth + "-" + myYear + " " + myHour + ":" + myMin + ":" + mySecond;

      }

   document.getElementById("frmCallBackDate").value = myVal;
 

 }

</script>

Open in new window

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
In this tutorial viewers will learn how to embed an audio file in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: : The declaration should display (CODE) HTML5 is supported by the most recent versions of all major browsers…
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 …

932 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

9 Experts available now in Live!

Get 1:1 Help Now