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
Solved

add code to onsubmit handler

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
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…

860 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