1

What I am trying to do is getting the same result as clicking on this following submit button.

<input id="submit_http:" class="add_submit" type="button" onclick="return dex.forms.form_ajax_submit(this,function(res) { alert('posting failed'); },function(res) { alert('posting success'); });" value="Next" name="submit_http:">

I was trying to do it like that:

$('.NextButton').click(function () {
    dex.forms.form_ajax_submit(document.getElementsByName('submit_http:'),
        function(res) { 
            alert('posting failed');
        }, 
        function(res) { 
            alert('posting success'); 
        });
});

But looks like document.getElementsByName is not returning the same result as the submit button 'this' How can I solve this issue?

3
  • 4
    Why on earth don't you want to use this? Commented Feb 29, 2012 at 12:53
  • because i cant use since it won't relate to the "submit" button but to the "NextButton" Commented Feb 29, 2012 at 12:54
  • do you check it with document.getElementsById ? Commented Feb 29, 2012 at 12:55

4 Answers 4

2

The only actual mistake you made was using the function document.getElementsByName, because it returns an array of elements (as indicated by the plural). What you need is a single element.

Either access the first element of the array by using:

document.getElementsByName('submit_http:')[0]

or use the already recommended and more precise function:

document.getElementById('submit_http:')
Sign up to request clarification or add additional context in comments.

Comments

1

document.getElementsByName('submit_http:') will return an array of elements that have that name. If you want to get your submit button, you want to use document.getElementsByName('submit_http:')[0].

Comments

1

While Anthony Grist is correct, in your case, since you already have an id for your input, you could do document.getElementById('submit_http:') (which returns a single element).

Comments

0

generally, we use a "self" variable for this. Before the submit, do that :

var self = this;

then use "self" into your callback

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.