views:

12

answers:

1

Hi I want to fire a button using a JavaScript, I founded several references on the web, but on the implementation I have an issue. I will use it for several buttons, the result if I press the real button is that I can "get" the information of what button was pressed using asp request("submit"), but if the JavaScript fires the button, the request("submit") returns an empty string. Any idea?

Example (please try) if I click the button I get the name, if I click the link, the page reload with an empty "x1" value, I tryied to use "history.go();" after the click, but nothing, I try with getelementbyid and directly the button...nothing again.

Any idea or help?

<% response.write "submit value " & request("x1") & "<br>" %>
<a href='' OnClick='document.myForm.x1.click();'>SAVE</a>
<br>
<form name=myForm method=post>
<input type=submit name=x1 id=theSubmitButton value='Button'>
</form>
+1  A: 

Change your link slightly, like this:

<a href='#' onclick='document.myForm.x1.click();'>SAVE</a>

Though this isn't the way I'd go about it, it fixes your current issue...right now (with an empty href) the link is just reloading the page, not submitting at all, you need a href="#" to prevent that behavior.

Nick Craver
thanks it worked
maca
@maca - welcome :) be sure to accept answers to your questions!
Nick Craver