SuperNinja
SuperNinja

Reputation: 1596

Mootools: Add input text field

I am using the mootools framework to add text inputs to a form. Here is my code:

http://jsfiddle.net/dazaweb/wjMJt/2/

As you can see, the input field appears for a sec, then disappears. Any ideas on why this is happening?

Thanks

Upvotes: 0

Views: 477

Answers (2)

Simon Edström
Simon Edström

Reputation: 6619

You are clicking on a submit button which will POST the form. Change the input type to button and it will work. Or you can prevent the default behaivor if you still want to use a submit button.

Here is a working link with a button insteed of submit:

http://jsfiddle.net/wjMJt/3/

You can also prevent the default behavoir by cancel the bubbling.

Just add e.stop(); inside your function, and pass the event argument as a variable named e like this:

$('btnAddOption').addEvent('click', function(e) {

Example:

http://jsfiddle.net/wjMJt/6/

Upvotes: 2

Sandeep Rajoria
Sandeep Rajoria

Reputation: 1239

add this in the javascript code

event.stop();

also pass event in the event handler

$('btnAddOption').addEvent('click', function(event) {

as by default the button supposed to submit the form which it is doing, but by doing event.stop we are preventing it to submit the form

My bad i wrote jquery ....updated it to javascript

Upvotes: 0

Related Questions