9 Replies - 515 Views - Last Post: 04 March 2014 - 12:57 AM

#1 mvelazquez  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 27-February 14

Alternative to RegisterOnSubmitFunction(...);

Posted 27 February 2014 - 07:00 PM

First of all , greetings to all .

I opened this topic to see if someone can support me in the following issue .

I've been using for several years a system which I program processes, which I have no access to the code. On the client side allows me to create forms in which I can use javascript and the system adds the Submit button to the form, which I have no control to.

Today I am migrating to a new version of the system and I have to develop some forms. A function widely used to perform calculations and also validate information was complex fields : RegisteronsubmitFunction(...);


This feature helped me at the time of executing the submit button, perform some function and return false if not validate anything. stopping the form prosesing.

The problem is that in the new instance no longer uses buttons Input type, but the label <button>

Before it was as follows :

Reviewing the source code, the button was so

<input type="submit" name="button" id="button" value="Submit" />


and the code I entered was inserted into the body

<body> ..

//Here I was programming my form

<script type="text/javascript">

function process () {
.....
}

RegisteronsubmitFunction ( process );

< / SCRIPT >

<body>


But now the button is as follows:


< div class = "x -btn x -btn -blue -button -small x -box- item x -toolbar -item x -btn -default -toolbar -small x - noicon x -btn - noicon x -btn -default- noicon -small- toolbar "style = " border -width: 1px ; border-color : rgb (209 , 209, 209 ) important , display : none ; "id =" button- 1391 ">
   <em id="button-1391-btnWrap">
      <button id="button-1391-btnEl" type="button" class="x-btn-center" hidefocus="true" role="button" AUTOCOMPLETE="off">
         <span id="button-1391-btnInnerEl" class="x-btn-inner" style=""> Submit< / span >
         <span id="button-1391-btnIconEl" class="x-btn-icon "> < / span >
      < / button>
   < / em >
< / div >


And when I try to use RegisteronsubmitFunction not work

An alternative method that comes to mind?

Is This A Good Question/Topic? 0
  • +

Replies To: Alternative to RegisterOnSubmitFunction(...);

#2 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3554
  • View blog
  • Posts: 10,335
  • Joined: 08-June 10

Re: Alternative to RegisterOnSubmitFunction(...);

Posted 27 February 2014 - 10:14 PM

Quote

An alternative method that comes to mind?

you don’t need a Framework to add a submit handler to a form. just define the handler directly via addEventListener() or onsubmit (depending on the old versions of browsers you have to support).
Was This Post Helpful? 0
  • +
  • -

#3 mvelazquez  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 27-February 14

Re: Alternative to RegisterOnSubmitFunction(...);

Posted 27 February 2014 - 10:59 PM

Hi Dormilich Thank you very much for the reply, I will try to addEventListener () since on​Submit () not working

This post has been edited by Dormilich: 27 February 2014 - 11:11 PM
Reason for edit:: made the capital S of onSubmit visible

Was This Post Helpful? 0
  • +
  • -

#4 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3554
  • View blog
  • Posts: 10,335
  • Joined: 08-June 10

Re: Alternative to RegisterOnSubmitFunction(...);

Posted 27 February 2014 - 11:09 PM

View Postmvelazquez, on 28 February 2014 - 06:59 AM, said:

since on​Submit () not working

of course not, there is no such function or method in Java­Script.

bear in mind that addEventListener() is not a standalone function either.

This post has been edited by Dormilich: 27 February 2014 - 11:10 PM

Was This Post Helpful? 0
  • +
  • -

#5 mvelazquez  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 27-February 14

Re: Alternative to RegisterOnSubmitFunction(...);

Posted 28 February 2014 - 07:03 PM

The idea of ​​eventListener took me to see this and other options and found a feature that was very useful to me and I was able to solve the problem. I do not know if it is the best option but I will temporarily:

Seeking all Span tags, and if the inside text is Submit, took the ID

I had to use the "parent" because I realized that my code was within a iFame

var inputs = parent.document.getElementsByTagName("span");

for (var i = 0; i < inputs.length; i++) {

  tagBoton = inputs[i].id;
	if(tagBoton != "")
		if(parent.document.getElementById(tagBoton).textContent == "Submit")
			idBoton = parent.document.getElementById(tagBoton).id;
		
	
}

document.getElementById(idBoton).onclick=function(){procesar()};


Was This Post Helpful? 0
  • +
  • -

#6 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3554
  • View blog
  • Posts: 10,335
  • Joined: 08-June 10

Re: Alternative to RegisterOnSubmitFunction(...);

Posted 28 February 2014 - 11:16 PM

View Postmvelazquez, on 01 March 2014 - 03:03 AM, said:

document.getElementById(idBoton).onclick=function(){procesar()};


unless you’ll be using this in the function (which I doubt), you can shorten that to
document.getElementById(idBoton).onclick=procesar;

Was This Post Helpful? 0
  • +
  • -

#7 mvelazquez  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 27-February 14

Re: Alternative to RegisterOnSubmitFunction(...);

Posted 03 March 2014 - 11:48 AM

Quote

unless you’ll be using this in the function (which I doubt), you can shorten that to
document.getElementById(idBoton).onclick=procesar;


Yes! it Wotks

This post has been edited by laytonsdad: 03 March 2014 - 11:58 AM
Reason for edit:: fixed tags

Was This Post Helpful? 0
  • +
  • -

#8 ge∅  Icon User is offline

  • D.I.C Addict

Reputation: 80
  • View blog
  • Posts: 575
  • Joined: 21-November 13

Re: Alternative to RegisterOnSubmitFunction(...);

Posted 03 March 2014 - 05:49 PM

Dormilich, you might be confusing the onclick HTMLElement property for the onclick HTML attribute. You can actually use the keyword 'this' with the syntax document.getElementById(idBoton).onclick=procesar; I do it all the time, I even prefer it over addEventListener.

mvelazqez, do you worship id attributes ? :P Just have a closer look at the following : getElementById(tagBoton).id
You select an element by its ID, then you request its ID. Man, you already have it !

Try to put it this way : you want to select span elements which contain the string "submit" and which are a direct child of a button element.

var inputs = document.getElementsByTagName("span");

for (var i = 0, j = inputs.length; i < j; i++) {    
    if(inputs[i].textContent=="Submit" && inputs[i].parentNode.nodeName=="BUTTON"){
        inputs[i].parentNode.onclick=procesar; // attach a click event to the targeted span's parent (the button element)
    }
}



One more thing : textContent does something very specific : it ignores tags. If you really need to ignore tags, use it, but if you only need to look for an element's content, prefer innerHTML. Seeing the textContent property in a script should warn you that there is some messy markup inside the targeted element. It's a valuable information when you read a code. If you use it all the time for no reason you won't notice this kind of subtleties. Moreover, it doesn't work in IE8 (a good enough reason to my mind).

This post has been edited by ge∅: 03 March 2014 - 05:51 PM

Was This Post Helpful? 0
  • +
  • -

#9 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3554
  • View blog
  • Posts: 10,335
  • Joined: 08-June 10

Re: Alternative to RegisterOnSubmitFunction(...);

Posted 03 March 2014 - 11:52 PM

View Postge∅, on 04 March 2014 - 01:49 AM, said:

Dormilich, you might be confusing the onclick HTMLElement property for the onclick HTML attribute.

definitely not.

View Postge∅, on 04 March 2014 - 01:49 AM, said:

You can actually use the keyword 'this' with the syntax document.getElementById(idBoton).onclick=procesar; I do it all the time, I even prefer it over addEventListener.

I never said you couldn’t use this. it only has different meanings when used in the attribute and in the property.

try this:
var proto = {
  getName : function() {
    alert("Hello, my name is " + this.name);
  }
}
var foo  = Object.create(proto);
foo.name = "John Doe";

// bar referring to the element <input type="text" name="Nickname">
bar.onblur = foo.getName;


This post has been edited by Dormilich: 03 March 2014 - 11:54 PM

Was This Post Helpful? 0
  • +
  • -

#10 ge∅  Icon User is offline

  • D.I.C Addict

Reputation: 80
  • View blog
  • Posts: 575
  • Joined: 21-November 13

Re: Alternative to RegisterOnSubmitFunction(...);

Posted 04 March 2014 - 12:57 AM

I guess I was tired ;) To add in my defence, it was a bit ambiguous
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1