Jump to content

Javascript Events


Recommended Posts

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!

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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.

Loading...
×
×
  • Create New...