asp button clicked as default - javascript

I'm working with asp classic, I have 2 form, the form1 has a button, if the user pressed it goes to the form2, and have to press another button called "consultar", but I want that pressing the first button, goes to the action of form2 without press the 2nd. button "consultar", I've tried onClick event, but doesn´t works, I need that button act as pressed and show something like been already pressed.can you help me? there is a javascript function for this?
here is my code:
<a href="index.asp?ia=100&r=g" onmouseout="MM_swapImgRestore();"
onmouseover="MM_swapImage('selector_r3_c2','','img/selector_r3_c2_s2.png',1);" >
<img name="selector_r3_c2" src="img/selector_r3_c2.png" width="168" height="55"
id="selector_r3_c2" alt="" /></a>
<input name="btConsultar" type="hidden" value="Consultar" onkeypress="Selected" /></td>

I don't know about javascript but you should be able to do something with classic asp and form variables and logical statements. eg form 1 could have a hidden attribute
<input type="hidden" name="buttonpressed" value="1" />
Then you could have an image button in form 2 as follows
<% if request.form("buttonpressed") = 1 then
submitbutton = "pressed.gif"
else
submitbutton = "unpressed.gif"
End If %>
<input type="image" src="<%=submitbutton%>" name="Consultar" />

Related

Set submit button to another when clicking enter

I'm trying to set the submit button in an ASP.NET website to another submit button when clicking enter key on the keyboard. I've so far accomplished to do so, but problem is it still sends the second submit button too. I tried returning false in the onkeypress event in the input elements, but then it won't let me write anything to the text input boxes..
This is my javascript function:
function button_click() {
if (window.event.keyCode == 13) {
document.getElementById("msSend").focus();
document.getElementById("msSend").click();
}
}
And a sample text input box:
<input type="text" id="msname" name="msname" runat="server" onkeypress="button_click()" /></td>
Any suggestions?
I fixed it! I had some buttons in my MasterPage that was for some reason defined as type="submit".
I changed:
<button name="bmenu" onclick="DisableHL('bmenu'); location.href='<%= movies %>'; return false;" class="btn">סרטים</button>
to:
<button name="bmenu" onclick="DisableHL('bmenu'); location.href='<%= movies %>'; return false;" class="btn" type="button">סרטים</button>
And there it fixed it! ;)

How to make a button to be clicked when enter is pressed using bookmarklet?

<td align="center" width="100%">
<input type="button" value=" Next " id="validate"><a id="new:new" href="#" onclick="mojarra.jsfcljs(document.getElementById('Form'),{'Form:Proceed':'Form:Proceed'},'');return false"></a>
<input id="Form:reset" type="submit" name="Form:reset" value="Reset">
</td>
This is the code above. I just want that after filling up the previous text field, when I press enter, the "Next" button gets clicked. Here "Reset" button is assigned as SUBMIT.
Please show me the javascript code using bookmarklet.
IF what I think you want is to:
have the code click the Submit button when the bookmarklet is clicked, the code I made below will do just that for you.
I URI encoded it for you so there shouldnt be any problems.
javascript:(function()%7Bdocument.getElementById(%22Form%3Areset%22).click()%7D)()

Force form to send certain submit button through (when there are multiple) when ENTER key pressed

I have a form with two submit buttons, name="submit_button" and name="search_me_logo", and when the form arrives at the action location, it does two different things depending on which button was pressed.
When the enter key is pressed, I want it to do the same thing as the name="submit_button" but right now it seems to be sending the name="search_me_logo" by default.
Here's the HTML code you need:
<form action="/search_me.php" method="GET">
<div id="search_me_outer_div">
<button id="search_me_div" name="search_me_logo" type="submit">
<img id="search_me_image" src="/images/header/search_icons/search_me.png" height="33" alt='"search me"'/>
</button>
</div><!--
--><div id="search_box_outer_div">
<div id="search_box_div">
<input id="search_box" onfocus="hidePlaceholderAndShineBox();" onblur="showPlaceholderAndBlurBox();" name="search" type="text" spellcheck="false" size="32" placeholder='Get to know Sam... "search me"'>
<button id="search_div" name="submit_button" type="submit">
<img id="search_img" src="images/header/search_icons/fancy_search.png" height="21" alt="Go"/>
</button>
</div>
</div>
</form>
PHP:
if (isset($_GET['submit_button'])) {
echo 'submit was pressed<br>';
} else if (isset($_GET['search_me_logo'])) {
echo 'logo was pressed<br>';
} else if (isset($_GET['search'])) {
echo 'enter was pressed<br>';
} else {
//show error page
}
Right now when I press enter, it echos "logo was pressed". There is probably a way with JavaScript, but if it's possible simply with HTML/PHP, that would be wonderful.
By default, hitting the enter key will cause the first submit button. You can simply add the default submit action in a hidden div right at the beginning of the form. For example:
<form action="/search_me.php" method="GET">
<div style="height:0px; width:0px; overflow:hidden;"><button id="search_div" name="submit_button" type="submit"></button></div>
and keep the rest as is.
Edit: some browsers won't let the enter key to trigger the first button if it's not displayed (e.g. display:none;).
However it will work with:
width: 0;
height: 0;
overflow: hidden;
In the CSS of the element that contains the hidden submit button.
Thanks for all the suggestions. #NoGray's answer could work or I just did two forms, as #Irdrah suggested.
Each forms' buttons and inputs had different names, and one of the inputs had a type="hidden" and id="hidden_input". Then when the submit for the form with the hidden input was clicked, I used jquery's submit() to set
document.getElementById('hidden_input').value = document.getElementById('shown_input').value;`
and returned true. I haven't tried #NoGray's but I'm sure it would work.

how can we provide different submit buttons in jsp, and execute respective page of button.?

I want to know how can we have different buttons in jsp, and how to submit the respective page for the button we pressed.
I have tried fallowing code :
<html>
<head> </head>
<body>
<%-- scriptlet here --%>
<%
if(request.getParameter("btnSubmit_1")!=null)
{
// means submit_1 is pressed.
// in java script we do give action as fallows
/**document.frm2.action="sub-faconline.jsp";
//document.frm2.target="right_f";
//document.frm2.submit();****
my question how can we do above java script code in scriplet in jsp
}
else if(request.getParameter("btnSubmit_2")!=null)
{
// i want to give some jsp page name here for action.
}
%>
<form name="frm2" method="post">
<input type="button" id="btnSubmit_1" name="btnSubmit_1" value="btnSubmit_1" />
<input type="button" id="btnSubmit_2" name="btnSubmit_2" value="btnSubmit_2"/>
</form>
</body>
</html>
You have to modify your html to this:
<form name="frm2" method="post" action="myJsp.jsp">
<input type="button" id="btnSubmit_1" name="btnSubmit_1" onClick="submitForm('btnSubmit_1'); value="btnSubmit_1"" />
<input type="button" id="btnSubmit_2" name="btnSubmit_2" onClick="submitForm('btnSubmit_2'); value="btnSubmit_2"/>
<input type="hidden" id="btnPressed" name="btnPressed" value=""/>
</form>
Javascript:
function submitForm(elem){
document.getElementById("btnPressed").value=elem;
document.frm2.submit();
}
And then in your jsp you can get the button value that was pressed using:
request.getParameter("btnPressed");
Explanation: Create an invisible input in the form that will hold the value of the btn. Then attach onclick functionality to each of the buttons that will set the value of the hidden input. And then submit the form to the form's action URL. Then in that url, you can get the hidden input's value(that contains the value of the button that was pressed)

Using two buttons (submit button and a normal button) which should submit the same form differently

I have used jquery wizard plugin to create this form.
The form get submitted when I use the ID = "next" submit button.
when I use the ID = "quick" button it will redirect to the Feedback.Form but it will not submitted properly. (I cant see the db has been updated properly.)
$j("#quick").click(function(){
$j('#feedbackForm').submit();
});
<form id="feedbackForm" method="post" action="<openmrs:contextPath/>/module/feedback/addFeedback.form" class="bbq" enctype="multipart/form-data" >
<div id="bottomNavigation">
<input id="back" value="Back" type="reset" />
<input id="next" value="Next" type="submit" />
<input id="quick" value="Just submit now with all the defaults!" type="button" />
</div>
Please can any one help me on this?
Thanks,
Harsha
Full source : https://gist.github.com/3227043
Convert the "next" button to normal button and add and if or switch selection into the jquery code. So both buttons were normal and Jquery will decide which ones takes to submit getting the name of the button who calls the click event. Or you can do it trough a javascript function, well, you can do it in any way as you want, but both buttons must be "button" type

Categories