anibaldps Posted August 30, 2011 Report Share Posted August 30, 2011 What other event can i have Javascript Code so it can run almost the same time as the "onsubmit" event. The reason is that my Javascript is more than 10,000 characters limit so i would like to split the code and run half of it on another Javascript Event. I dont have access to store files in the server so the external referencing file is not an option for me. I was thinking is there like a "onclick" event that runs before the "onsubmit"? How is it written? Please Help! Quote Link to comment Share on other sites More sharing options...
ShWolf Posted August 31, 2011 Report Share Posted August 31, 2011 Hi, You can save your external JS file on any other server (for example Dropbox etc.) and then reference it from your DataPage as described here: http://forums.caspio.com/viewtopic.php?p=15628#p15628 You can also split the script into several pieces (functions) and insert them as several HTML blocks. Hope this helps. Quote Link to comment Share on other sites More sharing options...
anibaldps Posted September 1, 2011 Author Report Share Posted September 1, 2011 Thank you for your reply. Can you please write an example of how do i split the code into functions? How do i make the call of the second function inside the first function?? Can the two functions run in the "onsubmit" event? In html block 1 i would have something like this: <SCRIPT> function actualizar(){ var currentTime = new Date() var month = currentTime.getMonth() + 1 var day = currentTime.getDate() var year = currentTime.getFullYear() var hours = currentTime.getHours() var minutes = currentTime.getMinutes() if (minutes < 10){ minutes = "0" + minutes } var fecha = month+"/"+day+"/"+year+" "+hours+":"+minutes; } ...second function call ... (how do i write it) document.getElementById("caspioform").onsubmit=actualizar; </SCRIPT>In html block 2 maybe something like this: <SCRIPT> function otraActualizacion(){ var user=document.getElementById("cbParamVirtual2").value; var Status_Viejo=document.getElementById("cbParamVirtual1").value; var Status=document.getElementById("EditRecordStatus").value; if(Status=="Cotizaciones recibidas"){ var Cotizacion1=document.getElementById("EditRecordCotizacion1").value; if(Cotizacion1>0){ var Timestamp_Cotizaciones_Recibidas=document.getElementById("EditRecordTimestamp_Cotizaciones_Recibidas"); document.getElementById("EditRecordTimestamp_Cotizaciones_Recibidas").value=fecha; var user_Cotizaciones_Recibidas=document.getElementById("EditRecorduser_Cotizaciones_Recibidas"); document.getElementById("EditRecorduser_Cotizaciones_Recibidas").value=user; } else{ alert("Error! Debe llenar al menos una cotizacion, el Status no sera actualizado"); document.getElementById("EditRecordStatus").value=""; return; } } } document.getElementById("caspioform").onsubmit=otraActualizacion; </SCRIPT> Please tell me if im doing it correctly. Thank you! Quote Link to comment Share on other sites More sharing options...
ShWolf Posted September 5, 2011 Report Share Posted September 5, 2011 I would suggest that for reusability purposes and easier maintainability you define a main function which would call all the child functions in the right order. An example goes below: HTML BLock 1: <script> function onCaspioFormSubmit() { firstFunction(); secondFunction(); } document.getElementById("caspioform").onsubmit = onCaspioFormSubmit; </script> HTML BLock 2: <script> function firstFunction() { // ... } </script> HTML BLock 3: <script> function secondFunction() { // ... } </script> Hope this helps. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.