Solved

add code to onsubmit handler

Posted on 2011-03-23
2
294 Views
Last Modified: 2012-05-11
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.

 
//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);

Open in new window


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.
0
Comment
Question by:brad0525
2 Comments
 
LVL 75

Accepted Solution

by:
Michel Plungjan earned 500 total points
ID: 35204514
I think you are looking for attachEvent
 However the code you have is ok and works so why mess with the two versions of attaching events you need, one for IE<9 and one for the rest?
0
 

Author Comment

by:brad0525
ID: 35216749
looking into it, its not perfect but i like the attachEvent way better.

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
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In this article, we'll look how to sort an Array in JavaScript, including the more advanced techniques of sorting a collection of records either ascending or descending on two or more fields. Basic Sorting of Arrays First, let's look at the …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

948 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now