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?
 
Chris StanyonCommented:
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
 
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 StanyonCommented:
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
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

 
goodkAuthor Commented:
want to see what was pressed On the server side? and without using the value?
0
 
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
 
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 StanyonCommented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.