Jump to content

Recommended Posts

I am modifying someone else's code to do this website and I am not sure how to do this correctly in html5 and php.

 

This is how it currently is.

/*------------------------------------------------------------------
      Begin to find start/end times

      NOTE: if s_date_time_opts is false we are editing all events and
            there will not be any data to get
    -------------------------------------------------------------------*/
if( $s_date_time_opts )
{
if( request_var('calAllDay', '') == "ON" )
{
$event_start_date = 0;
$event_end_date = 0;
$event_data['event_all_day'] = 1;
$event_data['event_day'] = sprintf('%2d-%2d-%4d', $date['day'], $date['month_no'], $date['year']);
$sort_timestamp = gmmktime( 0,0,0,$date['month_no'], $date['day'], $date['year']);
}
else
{
$start_hr = request_var('calHr', 0);
$start_mn = request_var('calMn', 0);
$event_start_date = gmmktime($start_hr, $start_mn, 0, $date['month_no'], $date['day'], $date['year'] ) - $user->timezone - $user->dst;
$sort_timestamp = $event_start_date;
$end_m = request_var('calMEnd', 0);
$end_d = request_var('calDEnd', 0);
$end_y = request_var('calYEnd', 0);
$end_hr = request_var('calHrEnd', 0);
$end_mn = request_var('calMnEnd', 0);
$event_end_date = gmmktime($end_hr, $end_mn, 0, $end_m, $end_d, $end_y ) - $user->timezone - $user->dst;
$event_data['event_all_day'] = 0;
$event_data['event_day'] = '';

// validate start and end times
if( $event_end_date < $event_start_date )
{
$error[] = $user->lang['NEGATIVE_LENGTH_EVENT'];
}
else if( $event_end_date == $event_start_date )
{
$error[] = $user->lang['ZERO_LENGTH_EVENT'];
}
}
$event_data['event_start_time'] = $event_start_date;
$event_data['event_end_time'] = $event_end_date;
$event_all_day = $event_data['event_all_day'];
$event_day = $event_data['event_day'];
}
    /*------------------------------------------------------------------
      End start/end times
    -------------------------------------------------------------------*/ 

and an input field in the same php file

$all_day_check = "<input type='checkbox' name='calAllDay' value='ON' clicked='clicked' onclick='toggle_all_day_event()' />";

some javascript in the html file

  function toggle_all_day_event()
  {
    if( document.postform.calAllDay.checked )
    {
      document.postform.calMEnd.disabled=true;
      document.postform.calDEnd.disabled=true;
      document.postform.calYEnd.disabled=true;
      document.postform.calHr.disabled=true;
      document.postform.calMn.disabled=true;
      document.postform.calHrEnd.disabled=true;
      document.postform.calMnEnd.disabled=true;
    }
    else
    {
      document.postform.calMEnd.disabled=false;
      document.postform.calDEnd.disabled=false;
      document.postform.calYEnd.disabled=false;
      document.postform.calHr.disabled=false;
      document.postform.calMn.disabled=false;
      document.postform.calHrEnd.disabled=false;
      document.postform.calMnEnd.disabled=false;
    }
  }

and some html further down in the html file

  <fieldset class="fields1">
	<dl style="clear: left;">
		<dt><label>All Day Event:</label></dt>
		<dd>{ALL_DAY_CHECK}</dd>
	</dl>
  </fieldset>

First off I would like the All Day Event checkbox currently on the page to be hidden and unchecked by default, or baring that unchecked and the disabled fields to be enabled and if checked later to disable the fields.

 

 

I thought I might be able to initialize the calAllDay variable earlier in the php file with this 

// Intialize Calendar All Day Event to Off
$calAllDay = 'OFF';

and change the input checkbox to this

$all_day_check = "<input type='checkbox' name='calAllDay' value='ON' onclick='toggle_all_day_event()' />";

but the behavior of this sets the checkbox to unchecked (like I could live with) but the disabled fields in the form are still disabled untill I check the checkbox and then uncheck it again.  I want the fields to be enabled on load.

Edited by psytae

Call the toggle_all_day_event() on page load (<body onload="toggle_all_day_event()">). When the page loads this function will be called and the other options will be enabled. As soon as you click the check box they should disable.

the <body > field is in my overall header file so if I added that <body onload="toggle_all_day_event()"> it would go off every page that was loaded which I don't want.

 

unless you can do a <body onload="toggle_all_day_event()"> inside another body in html I don't think that will work.  Doing some research on the onload function and I found that it should work with <script> as well so I tried chaing the php to

$all_day_check = "<input type='checkbox' name='calAllDay' value='ON' onclick='toggle_all_day_event()' />";

and the top of the html file

<script onload="toggle_all_day_event()" type="text/javascript">
  function toggle_all_day_event()
  {
    if( document.postform.calAllDay.checked )
    {
      document.postform.calMEnd.disabled=true;
      document.postform.calDEnd.disabled=true;
      document.postform.calYEnd.disabled=true;
      document.postform.calHr.disabled=true;
      document.postform.calMn.disabled=true;
      document.postform.calHrEnd.disabled=true;
      document.postform.calMnEnd.disabled=true;
    }
    else
    {
      document.postform.calMEnd.disabled=false;
      document.postform.calDEnd.disabled=false;
      document.postform.calYEnd.disabled=false;
      document.postform.calHr.disabled=false;
      document.postform.calMn.disabled=false;
      document.postform.calHrEnd.disabled=false;
      document.postform.calMnEnd.disabled=false;
    }
  }
}

page loads just fine with no errors, the checkbox is unchecked, like before, but the fields on page load are still disabled until I click the checkbox to turn it on once and then off.  Its like it doesn't know how to process NULL and treats it like its ON/Checked even though it isn't yet.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.