Solved

add code to onsubmit handler

Posted on 2011-03-23
2
299 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

The Ultimate Checklist to Optimize Your Website

Websites are getting bigger and complicated by the day. Video, images, custom fonts are all great for showcasing your product/service. But the price to pay in terms of reduced page load times and ultimately, decreased sales, can lead to some difficult decisions about what to cut.

Question has a verified solution.

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

Avoid defining the variables in the global scope; trying to define them in a local function scope. Because:   • Look-up is performed every time a variable is accessed.   • Variables are resolved backwards from most specific to least specific scope…
This article discusses how to create an extensible mechanism for linked drop downs.
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…

707 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