brad0525
asked on
add code to onsubmit handler
I am currently making a wysiwyg editor for an application, and trying to keep it as unobtrusive as I can.
the type of code I keep running into (which does work) looks like.
this code takes the value of the wysiwyg_editor and puts it into the wyswyg_input to be sumbitted by a form. The i value is saying which wysiwyg_editor on the page it is because i loop through every one and assign this when they are created.
This code just is hard for me follow and although it does work i am looking for a better way of doing it.
the type of code I keep running into (which does work) looks like.
//set to always drop content into input box onsubmit;
document.getElementById('wysiwyg_input:'+i).form.onsubmit = (
function(i,old_onsubmit) {
return function(){
if(document.getElementById('wysiwyg_input:'+i))
document.getElementById('wysiwyg_input:'+i).value = document.getElementById('wysiwyg_editor:'+i).innerHTML;
if(old_onsubmit) old_onsubmit();
}
}
)(i,document.getElementById('wysiwyg_input:'+i).form.onsubmit);
this code takes the value of the wysiwyg_editor and puts it into the wyswyg_input to be sumbitted by a form. The i value is saying which wysiwyg_editor on the page it is because i loop through every one and assign this when they are created.
This code just is hard for me follow and although it does work i am looking for a better way of doing it.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
it makes it easier to put it in an outside function and clean up the main script.
Thank you for pointing me in the right directions