Jump to content

Dynamic field creation issue


Nsm

Recommended Posts

I'm trying to edit this code to validate a date if its >90 days of today's date instead of a dropdown list.

Date has to be selected as follows: 
<input type="date" style="font-family:Arial, Helvetica; font-size:14px;" name="OrderDate">

If the selected date is > 90 days display option1 else display option 2
 


 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Dynamic field creation in PHP</title>
 
<script type="text/javascript" src="jquery.js"></script>
<script language="javascript">
function getXMLHTTP()
{
var xmlhttp=null;
try {
xmlhttp=new XMLHttpRequest();
}
catch(e)
{
try {
xmlhttp=new ActiveXobject("Microsoft.XMLHTTP");
}
catch(e)
{
try {
xmlhttp=new ActiveXObject("msxml2.XMLHTTP");
}
catch(e1)
{
xmlhttp=false;
}
}
}
return xmlhttp;
}
var strurl="dynamic-form.php?cate="+cat;
var req=getXMLHTTP();
function getCat(cat) {
//alert(cat);
                $("#flash").show();
                $("#flash").fadeIn(400).html('<img src="ajax-loader.gif" align="absmiddle"> loading.....');
var strurl="dynamic-form.php?cate="+cat;
//alert(strurl);
var req=getXMLHTTP();
if(req==null)
{
alert("browser error");
}
if(req)
{
req.onreadystatechange=function() {
if(req.readyState ==4 || req.readyState=="complete") {
               $("#flash").hide();
document.getElementById("ajaxresult").innerHTML=req.responseText;
}
}
req.open("GET",strurl,true);
req.send(null);
}
}
</script>
 
 
<link rel="stylesheet" type="text/css" href="css/style.css">
</head>
 
<body>
<div style="text-align:center;">
<div style="display:none;"><img src="ajax-loader.gif"  /></div>
  <h1 style="color:#CCC;">WORKFLOW</h1></div>
 
<table align="center" border="0" cellpadding="0" cellspacing="0" width="80%">
    <tr>
        <td id="Text1" width="15%" align="left" valign="middle">TODAYS DATE</td>
        <td id="Text1"width="2%" align="left" valign="middle">:</td>
        <td width="15%" align="left" valign="middle"> <?php echo date("d/m/Y");?>
</td>
        <td width="30%"> </td>
        <td width="20%"> </td>
    </tr>
    <tr>
        <td width="15%" align="left" valign="middle" id="Text1">ORDER DATE</td>
        <td width="2%" align="left" valign="middle" id="Text1">:</td>
        <td width="30%"> </td>
        <td width="20%"> </td>
    </tr>
    <tr>
        <td id="Text1" width="15%" align="left" valign="middle">SALES DISTRICT</td>
        <td id="Text1" width="2%" align="left" valign="middle">:</td>
        <td width="15%" align="left" valign="middle"><label>
      <select name="select" id="select"  onChange="getCat(this.value)">
        <option value="" selected="selected">Select Sales District</option>
        <option value="1">IN05</option>
        <option value="2">IN02</option>
        <option value="3">IN23</option>
        <option value="4">IN13</option>
<option value="5">EDU</option>
<option value="6">EPP</option>
      </select></label></td>
        <td width="30%"> </td>
        <td width="20%"> </td>
    </tr>
    <tr>
        <td align="left" valign="middle" colspan="5"><div id="flash"></div><div id="ajaxresult"></div></td></td>
        </tr>
</table>
 
 
</body>
</html>

Dynamic-form.php
 


<?php
$cat=$_REQUEST['cate'];
if($cat==1 || $cat==2 || $cat==3 || $cat==4)
{
require_once('OrderStatus.php');
}
elseif ($cat==5 || $cat==6)
{
require_once('NoVal1.php');
}
?>

Link to comment
https://forums.phpfreaks.com/topic/282759-dynamic-field-creation-issue/
Share on other sites

I have the following code:

 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Dynamic field creation in PHP</title>
 
<script type="text/javascript" src="jquery.js"></script>
<script language="javascript">
function getXMLHTTP()
{
var xmlhttp=null;
try {
xmlhttp=new XMLHttpRequest();
}
catch(e)
{
try {
xmlhttp=new ActiveXobject("Microsoft.XMLHTTP");
}
catch(e)
{
try {
xmlhttp=new ActiveXObject("msxml2.XMLHTTP");
}
catch(e1)
{
xmlhttp=false;
}
}
}
return xmlhttp;
}
var strurl="OrderDateForm.php?date="+date;
var req=getXMLHTTP();
function getDate(date) {
//alert(date);
                $("#flash").show();
                $("#flash").fadeIn(400).html('<img src="ajax-loader.gif" align="absmiddle"> loading.....');
var strurl="OrderDateForm.php?date="+date;
//alert(strurl);
var req=getXMLHTTP();
if(req==null)
{
alert("browser error");
}
if(req)
{
req.onreadystatechange=function() {
if(req.readyState ==4 || req.readyState=="complete") {
               $("#flash").hide();
document.getElementById("ajaxresult").innerHTML=req.responseText;
}
}
req.open("GET",strurl,true);
req.send(null);
}
}
</script>
 
 
<link rel="stylesheet" type="text/css" href="css/style.css">
</head>
 
<body>
<div style="text-align:center;">
<div style="display:none;"><img src="ajax-loader.gif"  /></div>
  <h1 style="color:#CCC;">WORKFLOW</h1></div>
 
<table align="center" border="0" cellpadding="0" cellspacing="0" width="80%">
    <tr>
        <td width="15%" align="left" valign="middle" id="Text1">ORDER DATE</td>
        <td width="2%" align="left" valign="middle" id="Text1">:</td>
        <td width="15%" align="left" valign="middle">
<input type="date" style="font-family:Arial, Helvetica; font-size:14px;" name="OrderDate"></td>
        <td width="30%"> </td>
        <td width="20%"> </td>
    </tr>
    <tr>
        <td align="left" valign="middle" colspan="5"><div id="flash"></div><div id="ajaxresult"></div></td></td>
        </tr>
</table>
 
 
</body>
</html>


OrderDateForm.php

[code]
<?php
$OrderDate = new DateTime('2014-01-31');
$today = new DateTime();
$days = $today->diff($OrderDate, 0);
 
if ($days->days > 90) 
{
require_once('VatValidation.php');
} 
else 
{
require_once('OrderDistrict.php');
}
?>
[/code]
 
 
VatValidation.php
 
[code]
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tr>
<td id="Text1" width="15%" align="left" valign="middle"><strong>CIRTIFICATE</strong></td>
<td id="Text1" width="2%" align="left" valign="middle">:</td>
<td width="15%" align="left" valign="middle"><label>
      <select name="select" id="select">
        <option value="" selected="selected"> </option>
        <option value="1">Yes</option>
        <option value="2">No</option>
        </select></label></td>
<td width="30%"> </td>
        <td width="20%"> </td>
    </td>
 
</tr>
</table>
[code]

 
 
OrderDistrict.php
 
[code]
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tr>
<td id="Text1" width="15%" align="left" valign="middle">SALES DISTRICT</td>
        <td id="Text1" width="2%" align="left" valign="middle">:</td>
        <td width="15%" align="left" valign="middle"><label>
      <select name="select" id="select"  onChange="getCat(this.value)">
        <option value="" selected="selected">Select Sales District</option>
        <option value="1">IN05</option>
        <option value="2">IN02</option>
        <option value="3">IN23</option>
        <option value="4">IN13</option>
<option value="5">EDU</option>
<option value="6">EPP</option>
      </select></label></td>
<td width="30%"> </td>
        <td width="20%"> </td>
    </td>
</tr>
</table>

I changed the code to select the date as follows:

<input type="date" style="font-family:Arial, Helvetica; font-size:14px;" name="OrderDate" onChange="getDate(this.value)">

It does display VatValidation.php no matter what date I enter.

I tried to edit the date in the below code but then it does not display anything at all. 

 

 

<?php
$OrderDate = new DateTime("2014-10-05");
$today = new DateTime();
$days = $today->diff($OrderDate, 0);
 
if ($days->days > 90) 
{
require_once('VatValidation.php');
} 
else 
{
require_once('OrderDistrict.php');
}
?>

How do I get it do compare the selected date to today's date, in order for it to display VatValidation.php in case the difference is > 90 days and if not for it to display OrderDistrict.php

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.