Solved

add code to onsubmit handler

Posted on 2011-03-23
2
293 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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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…

708 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

18 Experts available now in Live!

Get 1:1 Help Now