Applying JS to dynamically created vars

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Applying JS to dynamically created vars

Torrent Girl
Hello

I need help with an issue.

I am creating dynamically generated form fields so there can be 10 or 20 or 30 and so on (in groups of 10, and up to 50)

I need to apply javascript validation to those fields.

My question is how can I predict the number of fields there will be?

I need to do things such as this:

If field1 = "Null", Set field2, 3, 4, 5 to "NULL"


Thank you in advance for your help and I have a AM deadline ;)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Message: http://www.houseoffusion.com/lists.cfm/link=i:33:2730
Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/33
Subscription: http://www.houseoffusion.com/lists.cfm/link=s:33
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=17837.14401.33
Donations & Support: http://www.houseoffusion.com/tiny.cfm/54
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

RE: Applying JS to dynamically created vars

Phillip Holmes
You just loop over the form elements. In other words, use the form's number
of elements as your index and then use logic to determine what type of
element it is. Then you just validate them accordingly. Here is an example
using radio elements:


<script>
function checkform(obj_input) {
    var checked = 0;
    for (var i=0; i<obj_input.length; i++) {
                if(obj_input.elements[i].type == 'radio') {
                        if(obj_input.elements[i].checked == true) {
                                checked++;
                                break;
                        }
                }
    }
     if (checked == 0) {
          alert("you did not check a radio button");
          return false;
     }
     return true;
}
</script>



<form action="" method="post" onsubmit="return checkform(this)"
name="theform">
<input type="radio" name="arad" value="true"><input type="radio"
name="arad"value="false"><br />
<input type="text" name="atest" size="10"><br />
<input type="submit" value="submit">
</form>



Warmest Regards,
 
Phillip B. Holmes
http://phillipholmes.com
214-995-6175 (cell)



 

-----Original Message-----
From: Torrent Girl [mailto:[hidden email]]
Sent: Wednesday, June 14, 2006 8:35 PM
To: Javascript
Subject: Applying JS to dynamically created vars

Hello

I need help with an issue.

I am creating dynamically generated form fields so there can be 10 or 20 or
30 and so on (in groups of 10, and up to 50)

I need to apply javascript validation to those fields.

My question is how can I predict the number of fields there will be?

I need to do things such as this:

If field1 = "Null", Set field2, 3, 4, 5 to "NULL"


Thank you in advance for your help and I have a AM deadline ;)



~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Message: http://www.houseoffusion.com/lists.cfm/link=i:33:2734
Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/33
Subscription: http://www.houseoffusion.com/lists.cfm/link=s:33
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=17837.14401.33
Donations & Support: http://www.houseoffusion.com/tiny.cfm/54
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Applying JS to dynamically created vars

Torrent Girl
Ok thanks

I'll take a look and see how I can implement it.




>You just loop over the form elements. In other words, use the form's number
>of elements as your index and then use logic to determine what type of
>element it is. Then you just validate them accordingly. Here is an example
>using radio elements:
>
>
><script>
>function checkform(obj_input) {
>    var checked = 0;
>    for (var i=0; i<obj_input.length; i++) {
> if(obj_input.elements[i].type == 'radio') {
> if(obj_input.elements[i].checked == true) {
> checked++;
> break;
> }
> }
>    }
>     if (checked == 0) {
>          alert("you did not check a radio button");
>          return false;
>     }
>     return true;
>}
></script>
>
>
>
><form action="" method="post" onsubmit="return checkform(this)"
>name="theform">
><input type="radio" name="arad" value="true"><input type="radio"
>name="arad"value="false"><br />
><input type="text" name="atest" size="10"><br />
><input type="submit" value="submit">
></form>
>
>
>
>Warmest Regards,
>
>Phillip B. Holmes
>http://phillipholmes.com
>214-995-6175 (cell)
>
>
>
>
>
>-----Original Message-----
>From: Torrent Girl [mailto:[hidden email]]
>Sent: Wednesday, June 14, 2006 8:35 PM
>To: Javascript
>Subject: Applying JS to dynamically created vars
>
>Hello
>
>I need help with an issue.
>
>I am creating dynamically generated form fields so there can be 10 or 20 or
>30 and so on (in groups of 10, and up to 50)
>
>I need to apply javascript validation to those fields.
>
>My question is how can I predict the number of fields there will be?
>
>I need to do things such as this:
>
>If field1 = "Null", Set field2, 3, 4, 5 to "NULL"
>
>
>Thank you in advance for your help and I have a AM deadline ;)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Message: http://www.houseoffusion.com/lists.cfm/link=i:33:2744
Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/33
Subscription: http://www.houseoffusion.com/lists.cfm/link=s:33
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=17837.14401.33
Donations & Support: http://www.houseoffusion.com/tiny.cfm/54
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Applying JS to dynamically created vars

Torrent Girl
In reply to this post by Phillip Holmes
Here is the code I ended up with

function restoreDefaultValues(obj) {
                var getOriginalValue = parseInt(obj.name.substr(7, 2));
                if (obj.options[ obj.selectedIndex ].value != '') {
                        for (var i = 1; i<5; i++) {
                                var makeObj = 'Company' + eval(getOriginalValue + i);
                                document.getElementById( makeObj ).selectedIndex = 1;
                        }
                }
        }



Any ideas on how to calculate dynamic form fields?












>You just loop over the form elements. In other words, use the form's number
>of elements as your index and then use logic to determine what type of
>element it is. Then you just validate them accordingly. Here is an example
>using radio elements:
>
>
><script>
>function checkform(obj_input) {
>    var checked = 0;
>    for (var i=0; i<obj_input.length; i++) {
> if(obj_input.elements[i].type == 'radio') {
> if(obj_input.elements[i].checked == true) {
> checked++;
> break;
> }
> }
>    }
>     if (checked == 0) {
>          alert("you did not check a radio button");
>          return false;
>     }
>     return true;
>}
></script>
>
>
>
><form action="" method="post" onsubmit="return checkform(this)"
>name="theform">
><input type="radio" name="arad" value="true"><input type="radio"
>name="arad"value="false"><br />
><input type="text" name="atest" size="10"><br />
><input type="submit" value="submit">
></form>
>
>
>
>Warmest Regards,
>
>Phillip B. Holmes
>http://phillipholmes.com
>214-995-6175 (cell)
>
>
>
>
>
>-----Original Message-----
>From: Torrent Girl [mailto:[hidden email]]
>Sent: Wednesday, June 14, 2006 8:35 PM
>To: Javascript
>Subject: Applying JS to dynamically created vars
>
>Hello
>
>I need help with an issue.
>
>I am creating dynamically generated form fields so there can be 10 or 20 or
>30 and so on (in groups of 10, and up to 50)
>
>I need to apply javascript validation to those fields.
>
>My question is how can I predict the number of fields there will be?
>
>I need to do things such as this:
>
>If field1 = "Null", Set field2, 3, 4, 5 to "NULL"
>
>
>Thank you in advance for your help and I have a AM deadline ;)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Message: http://www.houseoffusion.com/lists.cfm/link=i:33:2878
Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/33
Subscription: http://www.houseoffusion.com/lists.cfm/link=s:33
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=17837.14401.33
Donations & Support: http://www.houseoffusion.com/tiny.cfm/54
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Large number of radio buttons have a performance hit

Purnima Singh
In reply to this post by Torrent Girl
Hi,
I am displaying number of records based on DB result, which is stored in a count variable of my form to set the value of three radio buttons in my form i am lopping though the count variable.My code works fantastic when there are less than 50 records, but if there are more there is a performance problem.....
Can anyone help me:
Below is my source code:
<html>
<head>
<title>Expiring Rates Update</title>
<link rel="stylesheet" type="text/css" href="../style.css">
<script language="JavaScript" type="text/JavaScript"> <!-- function MM_goToURL() { //v3.0 var i, args=MM_goToURL.arguments; document.MM_returnValue = false; for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'"); } //--> </script></HEAD>
<body bgcolor="#ffffff" link="#660099" vlink="#660099" >
<cfinclude template="../templates/headerTemplate.htm">
<cfinclude template="../cr/logagr.cfm">
<cfif not isdefined("rCounter")><cfabort></cfif>


<cfoutput>
<cfset found = 0>
<p>
<cfset agentlist = "">
<cfset extendOneYrVar =0> 
<cfset setNewExpVar=0>
<cfset donotextendVar=0>

<cfset ExtnOnYrArray = ArrayNew(1)>
<cfset SetNewDtArray= ArrayNew(1)>
<cfset DoNotExtnArray= ArrayNew(1)>
<cfset terridArray=ArrayNew(1)>
<cfset ExtnOnYrList="">
<cfset SetNewDtList="">
<cfset DoNotExtnList="">



<cfloop index="rowIndex" from = "1" to = "#rCounter#" >

  <cfset a_rowid  = ListToArray(rowidParm)>
  <cfset a_originalDate = ListToArray(originalDate)>
  <cfset a_agentname = ListToArray(agentname)>
  <cfset rowidOut  = a_rowid[#rowIndex#]>
  <cfset originalDateOut = a_originalDate[#rowIndex#]>
  <cfset agentnameOut = a_agentname[#rowIndex#]>
  <cfset originalDateOut = #RTrim(originalDateOut)#> 
  <cfset radioExtOneYr = "c1_" & variables.rowIndex>
  <cfset radioDonotExt="c2_"& variables.rowIndex>
  <cfset radioSetNewExp="c3_"& variables.rowIndex>
  <cfset expirationDateVal="expirationDateParm_"& variables.rowIndex>
  <cfset radioFlgN=#Evaluate('hidd_radioN_'& rowIndex)# >
  <cfset terrid=#Evaluate('terrOwner_'& rowIndex)#>
  <cfset temp = ArrayAppend(terridArray, "#terrid#")>
  <cfset terridList = ArrayToList(terridArray,',')>
  <cfset rowIdValue=#Evaluate('rowidVal_'& rowIndex)#>
 
  <cfif radioFlgN eq 'extendOneYear'>
   <cfset extendOneYrVar =extendOneYrVar + 1> 
  <cfset rowidValues=#Evaluate('rowidVal_'& rowIndex)#>
  <cfset temp = ArrayAppend(ExtnOnYrArray, "#rowidValues#")>
  <cfset ExtnOnYrList = ArrayToList(ExtnOnYrArray,',')>
 

 
  <cfoutput> I am here in extend on year function <br></cfoutput>
  <cfoutput> before email </cfoutput>
 
  <cfquery datasource="#eprice#" name="getExpDate">
     select trunc(expdate) expirationDt from afp_dba.agreed_rate
     where
     rowid = '#URLDecode(rowidOut)#'
  </cfquery>
  <cfoutput><br>url decode value of rowid #URLDecode(rowidOut)#<br></cfoutput>
 
  <cfset currExpDt= getExpDate.expirationDt>
 
  <cfset nowYear = #DateFormat(currExpDt,"YYYY")#>
  <cfset nowMonth = #DateFormat(currExpDt,"mm")#>
  <cfset nowDay = #DateFormat(currExpDt,"dd")#>
  <cfset scr = CreateDate(nowYear + 1,nowMonth,nowDay) >
  <cfset plusOneYear = #DateFormat(scr,"yyyymmdd")#>
 
 
 
   
  <cfset s = "Request extened for a year by:" & wsso_uid &  " Agent is:" & agentnameOut>
  <cfset #logf(s)#>
 

 
  <cfelseif radioFlgN eq 'setNewDate' and IsDefined(expirationDateVal)>
  <cfset setNewExpVar=setNewExpVar + 1>
  <cfset rowidValues=#Evaluate('rowidVal_'& rowIndex)#>
  <cfset temp1 = ArrayAppend(SetNewDtArray, "#rowidValues#")>
  <cfset SetNewDtList = ArrayToList(SetNewDtArray,',')>
  <cfoutput>the value of ExtnOnYrList 1 is #SetNewDtList#</cfoutput>
 
 
  <cfset expirationDate=#Evaluate('expirationDateParm_'& rowIndex)#>
 
 
  <cfset s = "Request extened  by:" & wsso_uid &  " Agent is:" & agentnameOut & " New Expiration Dt:" &expirationDate >
  <cfset #logf(s)#>
  <cfelseif  radioFlgN eq 'doNotExtend'>
  <cfset rowidValues=#Evaluate('rowidVal_'& rowIndex)#>
  <cfset temp3 = ArrayAppend(DoNotExtnArray, "#rowidValues#")>
  <cfset DoNotExtnList = ArrayToList(DoNotExtnArray,',')>
  <cfset donotextendVar=donotextendVar + 1>
  </cfif>
  <cfif radioFlgN eq ''> 
  <cfoutput>  NO UPDATE <br> </cfoutput>
  <cfelse>
  <cfset found = found + 1>
  <cfoutput>  UPDATE  <br> </cfoutput>     
  </cfif>

</cfloop>

 
<cfquery name="getOneyrExtendedValues1" datasource="#eprice#">
select s.empid, s.firstname, s.lastname, b.agentname, c.shippername
from afp_dba.agreed_rate a,
afp_dba.agent b,
afp_dba.shipper c,
afp_dba.product e,
afp_dba.territories s where
a.prodcode = e.prodcode
and a.agentid != '11111111'
and a.agentid !='22222222'
and a.agentid = b.agentid
and a.shipperid = c.shipperid
and a.origbase = s.territory
and s.empid in (#terridList#)
and a.rowid in ('#Replace (ExtnOnYrList,",", "','", "all")#')
group by s.empid, s.firstname, s.lastname, b.agentname, c.shippername
order by  1,4, 5
</cfquery>

<cfquery name="doNotExtendValues" datasource="#eprice#">
select s.empid, s.firstname, s.lastname, b.agentname, c.shippername
from afp_dba.agreed_rate a,
afp_dba.agent b,
afp_dba.shipper c,
afp_dba.product e,
afp_dba.territories s where
a.prodcode = e.prodcode
and a.agentid != '11111111'
and a.agentid !='22222222'
and a.agentid = b.agentid
and a.shipperid = c.shipperid
and a.origbase = s.territory
and s.empid in (#terridList#)
and a.rowid in ('#Replace (DoNotExtnList,",", "','", "all")#')
group by s.empid, s.firstname, s.lastname, b.agentname, c.shippername
order by  1,4, 5
</cfquery>


</cfoutput>

<cfloop query="getOneyrExtendedValues1" >
<cfquery name="getOneyrExtendedValuesEmial" datasource="#eprice#">
select s.empid, s.firstname, s.lastname, b.agentname, c.shippername ,
a.COMMODITY, a.MINWGT, a.TYPECODE, a.EFFDATE, a.EXPDATE, a.RATE, a.origbase,
a.MINCHRG, a.PIVOTWGT, a.WGTCODE, a.CURRENCY,
a.DESTBASE, a.expdate, a.delete_flag, e.prodname
from afp_dba.agreed_rate a,
afp_dba.agent b,
afp_dba.shipper c,
afp_dba.product e,
afp_dba.territories s where
a.prodcode = e.prodcode
and a.agentid != '11111111'
and a.agentid !='22222222'
and a.agentid = b.agentid
and a.shipperid = c.shipperid
and a.origbase = s.territory
and s.empid =#getOneyrExtendedValues1.empid#
and s.firstname ='#getOneyrExtendedValues1.firstname#'
and s.lastname ='#getOneyrExtendedValues1.lastname#'
and b.agentname ='#getOneyrExtendedValues1.agentname#'
and c.shippername  ='#getOneyrExtendedValues1.shippername#'
and (a.rowid in ('#Replace (ExtnOnYrList,",", "','", "all")#') or a.rowid in ('#Replace (SetNewDtList,",", "','", "all")#') )
</cfquery>

<cfset empidVal=#trim(getOneyrExtendedValues1.empid)#>
<cfoutput> the value of empid now is #empidVal#@fedex.comis <br></cfoutput>

<cfmail to="#empidVal#@fedex.com"
type="html"
from="ePrice@corp.ds.fedex.com"
subject=" Rate Extension Notification">


 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
 "http://www.w3.org/TR/html4/loose.dtd">
 <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

 <style type="text/css"> <!-- .mailit { font-family: Arial, Helvetica, sans-serif; font-size: 12px; } .warning { FONT-WEIGHT: bold; FONT-SIZE: 12px; COLOR: red; FONT-FAMILY: Arial, Helvetica, Verdana, sans-serif} .lb { border-style: solid; border-color: ##c0c0c0; border-width: 1; border-padding: 2; font-family: Arial, Helvetica, sans-serif; font-size: 12px; } --> </style> <p class="mailit">
 The following rates have been extended:
 </p>
 


<cfloop query="getOneyrExtendedValuesEmial">
                 </cfloop>
AGENTSHIPPERORGDESTPRODUCTCOMMODITYTYPEWGTPIVOTWCRATEMIN CHGCUREFFECTIVEEXPIRE
#agentname##shippername##origbase##DESTBASE##prodname##COMMODITY##TYPECODE##MINWGT##PIVOTWGT##WGTCODE##RATE##MINCHRG##CURRENCY##DateFormat(EFFDATE,'YYYYMMDD')##DateFormat(EXPDATE,'YYYYMMDD')#
<p class="mailit">ePrice Administration</p>
</cfmail>
</cfloop>


<cfloop query="doNotExtendValues" >
<cfquery name="doNotExtendedValuesEmial" datasource="#eprice#">
select s.empid, s.firstname, s.lastname, b.agentname, c.shippername ,
a.COMMODITY, a.MINWGT, a.TYPECODE, a.EFFDATE, a.EXPDATE, a.RATE, a.origbase,
a.MINCHRG, a.PIVOTWGT, a.WGTCODE, a.CURRENCY,
a.DESTBASE, a.expdate, a.delete_flag, e.prodname
from afp_dba.agreed_rate a,
afp_dba.agent b,
afp_dba.shipper c,
afp_dba.product e,
afp_dba.territories s where
a.prodcode = e.prodcode
and a.agentid != '11111111'
and a.agentid !='22222222'
and a.agentid = b.agentid
and a.shipperid = c.shipperid
and a.origbase = s.territory
and s.empid =#doNotExtendValues.empid#
and s.firstname ='#doNotExtendValues.firstname#'
and s.lastname ='#doNotExtendValues.lastname#'
and b.agentname ='#doNotExtendValues.agentname#'
and c.shippername  ='#doNotExtendValues.shippername#'
and a.rowid in ('#Replace (DoNotExtnList,",", "','", "all")#')
</cfquery>


<cfset empidVal=#trim(doNotExtendValues.empid)#>
<cfoutput> the value of empid now is #empidVal#@fedex.comis <br></cfoutput>

<cfmail to="#empidVal#@fedex.com"
type="html"
from="corp.ds.fedex.com"
subject=" Rate Expiration Notification">


 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
 "http://www.w3.org/TR/html4/loose.dtd">
 <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

 <style type="text/css"> <!-- .mailit { font-family: Arial, Helvetica, sans-serif; font-size: 12px; } .warning { FONT-WEIGHT: bold; FONT-SIZE: 12px; COLOR: red; FONT-FAMILY: Arial, Helvetica, Verdana, sans-serif} .lb { border-style: solid; border-color: ##c0c0c0; border-width: 1; border-padding: 2; font-family: Arial, Helvetica, sans-serif; font-size: 12px; } --> </style><p class="mailit">
 The following rates have or will expire:
</p>
                
<cfloop query="doNotExtendedValuesEmial">
                 </cfloop>

AGENTSHIPPERORGDESTPRODUCTCOMMODITYTYPEWGTPIVOTWCRATEMIN CHGCUREFFECTIVEEXPIRE
#agentname##shippername##origbase##DESTBASE##prodname##COMMODITY##TYPECODE##MINWGT##PIVOTWGT##WGTCODE##RATE##MINCHRG##CURRENCY##DateFormat(EFFDATE,'YYYYMMDD')##DateFormat(EXPDATE,'YYYYMMDD')#
 <p class="mailit">ePrice Administration</p>
</cfmail>
</cfloop>

<cfif found eq 0>
 
 
 
<cfelse>
   
 <cfoutput>  <br><br>UPDATES ARE THERE  <br> </cfoutput>
 <cfif found gt 1> 
 </cfif>
</cfif>

 
 <cfabort>
 

 

</body>

</html>

 
Please help me.
thanks a lot.
Regards,
Purnima
Loading...