In javascript how do I fetch <input type="submit" name="IPressedA"> <input type="submit" name="IPressedB">

How do you fetch values so you know which button has been pressed?
goodkAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Tom BeckCommented:
Assuming your form tag has method="get", the pressed submit button will appear in the window.location.search part of the URL.

Given the following form:

<form id="frm" name="frm" method="get" action="#">
            <input type="submit" name="IPressedA" value="Submit A"> <input type="submit" name="IPressedB" value="Submit B">
</form>

Resulting URL when pressing the "B" submit button:

http://myDomain.com/teststuff_43.html?IPressedB=Submit+B#
0
Chris StanyonWebDevCommented:
Add an onclick attribute and pass in the button. In the function, grab the name property:

<input type="submit" name="IPressedB" onclick="myfunc(this)" />

function myfunc(button) {
 alert(button.name);   
}

Open in new window


Working Demo: http://jsfiddle.net/ChrisStanyon/u8krxong/
0
goodkAuthor Commented:
want to see what was pressed On the server side? and without using the value?
0
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

Tom BeckCommented:
Then just method="post". Post everything.

What server side technology? PHP?
0
goodkAuthor Commented:
HttpContext.Current.Request.Form["_TableHeaders"];    

The above works fine in asp.net

I wanted to know what is the equivalent of this in javascript?
0
Tom BeckCommented:
There isn't any. Javascript is a client side technology. Only server side technologies such as asp.net and php can receive and handle data posted from a web form. This: HttpContext.Current.Request.Form["_TableHeaders"]; uses the post method.

You have two choices demonstrated above for determining which button was clicked but the server is completely ignorant of what's going on with the client's browser.
0
Chris StanyonWebDevCommented:
Might help here if you tell us what it is you're trying to achieve and we can then offer our suggestions.

As Tom has already pointed out - Javascript is purely client-side (i.e in the browser). For server-side processing you'd use something like PHP or ASP. An html form is sent to the server for processing using either a POST request or a GET request, and you can then query the form to figure out which button was pressed.

You can sort of combine the client-side / server-side using something called AJAX - this uses javascript in the client, to send data to the server, but unless we have more of an idea of what you need, we can't really give you specific guidance.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
goodkAuthor Commented:
thanks, guys.  

I always wonder why JAVASCRIPT was never made into a complete language?  So you do not need php or asp.
0
goodkAuthor Commented:
Ok, experts if you say that javascript cannot capture event like what button was pressed then how autocomplete  in jquery would work?
0
Chris StanyonWebDevCommented:
Hey goodk - that's a completely different issue so you would need to open a new question.

To get you started, have a look at the Autocomplete widget from the jQuery UI library:

http://jqueryui.com/autocomplete/
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.