troubleshooting Question

javascript: change the onClick event dynamically

Avatar of KeithMcElroy
KeithMcElroy asked on
JavaScriptWeb Components
4 Comments3 Solutions665 ViewsLast Modified:
The onClick event is dynamically created at load time.  Inside the onclick event is a value similar to the following  table_field_1.  Each time a new row is created, the onclick event needs to have table_field_1 changes to table_field_2, table_field_3 and so on.

The code I included has issues because the getAttribute("onCick") returns the keyword function.  If I could get it to return just the actual content of the onClick, I think it could work.

Need help shaping this solution.
if(els[el].id.indexOf("anchor") > -1)
			{
				//sample code that needs to be manipulated...
				// onClick=cal.select(document.forms['WebForm']." & fieldelement.getAttribute("id")  & ",'anchor1','MM/dd/yyyy'); return false

				//retrieve the onClick event as text and determin the begin and end point for the number following the last underscore
				//var starttargpos = els[el].getAttribute("onClick").lastIndexOf("_") 
				//var stoptargpos =  els[el].getAttribute("onClick").indexOf(",'anchor1") 
				
				//parse out the text to the left and the text representing the number to be changes
				//lefttext = els[el].getAttribute("onClick").substring(0,starttargpos - 1)
				//targettext = els[el].getAttribute("onClick").substring(starttargpos,stoptargpos)
				
				//increment the number and retrieve the text to the right
				//newtargettext = Number(targettext) + 1
				//righttext = els[el].getAttribute("onClick").substring(stoptargpos + 1)
				
				//reassemble the left, target and right together and assign to the onClick attribute
				//newonclick = lefttext + newtargettext + righttext
				
				//els[el].getAttribute("onClick") = els[el].getAttribute("onClick")
							
			}
ASKER CERTIFIED SOLUTION
jb1dev

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 3 Answers and 4 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 3 Answers and 4 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros