|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Trying to understand javascript code?
Hi,
I am trying to understand this piece of code. what are they doing here on line 1, 2 and 3 var f = $('form'); f.old_onsubmit = f.onsubmit; f.onsubmit = function() { if(evaluate_required_fields_ajax()) { return true; } else { return false; } } Thanks |
|
#2
|
||||
|
||||
|
On line...
1) They are using a function from a JavaScript library to get an object reference. 2) They are saving the old onsubmit handler as a new property of the form. 3) They are creating a new onsubmit handler.
__________________
Spreading knowledge, one newbie at a time. Learn CSS. | PHP includes | X/HTML Validator | CSS validator | Dynamic Site Solutions Design/program for Firefox (and/or Opera), apply fixes for IE, not the other way around. Check out my blog. |
|
#3
|
|||
|
|||
|
Thanks for your reply, what is "onsubmit handler" ?
|
|
#4
|
||||
|
||||
|
You're welcome
![]() A form has several events that you can attache functions to that will do something when that event occurs. One of these events is the onsubmit event that is triggered via a input/button of type="submit" or when someone presses the enter key from within a non-<textarea> form control. This event allows you to pre-validate the form before the server processes it. |
|
#5
|
|||
|
|||
|
thanks, i was familar with the term event like onload, onclick etc. but did not know that we also use the term handler for that as well.
now for this f.old_onsubmit = f.onsubmit; you said "They are saving the old onsubmit handler as a new property of the form." what exactly you mean by that, I mean suppose form has 3 text boxes(text1,text2, text3), we submit this form. Now are you saying that old_onsubmit will have all those text boxes and we can refer to them by using f.old_onsubmit.text1 ..something like that ..... thats where I got lost |
|
#6
|
||||
|
||||
|
You are very lost.
The onsubmit handler is merely a JavaScript function that runs before the form is submitted to a server for processing. It can be used to stop the form submission so a user can correct a mistake in filling out the form. Since JavaScript can be disabled, you should always validate on the server, even if you validate with JavaScript as well. It does not contain the name/value pairs of the form controls. They made a copy in case they wanted to change back to the old onsubmit handler. |
![]() |
| Viewing: Dev Shed Forums > Web Design > JavaScript Development > Trying to understand javascript code? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|