Href link on input button submit - html

How can i bind this link
<a href="edit?id=<c:out value='${person.id}' />">
to input button "submit" ?

try something like that. Hope this will fix your problem
href="\edit?id={{person.id}}"

Typically if you are using a submit button, then you will be inside a form. An example of this would be:
<form action="edit?id=<c:out value='${person.id}' />" method="post">
<!-- form fields here -->
<input type="submit" value="Submit" />
</form>
In this case, the submit button is "tied" to the form, and will post the form data to the link in the action value.

I found solution :
<input type="hidden" name="from" value="${param.from}">
Servlet.class
response.sendRedirect(request.getParameter("from"));

Related

Two forms on one page causes wrong validation

I have one page with two separate forms. Most input fields are required. When I click the submit button on the second form, it asks me to fill out the required fields in the first form.
How do I make sure that it only validates the form in which I clicked the submit button?
<form method="post" action="index.php" name="orderQuick" id="orderQuick">
<input type="text" name="street" id="street" required>
<button type="submit" name="submitBtn" id="submitBtn">Submit</button>
</form>
<form method="post" action="index.php" name="order" id="order">
<input type="text" name="street2" id="street2" required>
<button type="submit" name="submitBtn2" id="submitBtn2">Submit</button>
</form>
I think it is because you have not closed <button> tag so it is considering both input type in one form. Close <button> tag.I think it will solve your issue.
I think you will need to use the jqueryvalidation plugin: (http://jqueryvalidation.org/valid/)
Using this plugin, on the click of the respective submit buttons, you just need to call the method:
$("#orderQuick").valid();
and
$("#order").valid();
This should solve your issue.

How can I make an html button that passes a parameter?

I want a html button with parameter functionality.
new/?sorting=desc is the url that it should link to. But when I try, the parameter is not passed. How should it be done? I tried both the methods below but none worked.
<FORM METHOD="GET" ACTION="./?sorting=desc">
<INPUT TYPE="submit" VALUE="Äldst först">
</FORM>
I want buttons that behave like these links:
Äldst först
Nyast först
If you want something to act as a link, then you should use a link.
That said:
When you submit a GET form, the query string is removed from the action and a new one is generated from the data in the form.
You need to store the data in hidden inputs.
<form action="/social/tracking/new/">
<input type="hidden"
name="sorting"
value="desc">
<input type="submit"
value="Nyast först">
</form>
<form action="/social/tracking/new/">
<input type="hidden"
name="sorting"
value="asc">
<input type="submit"
value="Sort the other way">
</form>
If you are using jQuery, you can use the code below.
This will fill a hidden input with the correct value when you click on one of the submit buttons.
<form method="get" action="./">
<input type="hidden" name="sorting" id="sorting" value="" />
<input type="submit" value="Äldst först" id="sort_desc" />
<input type="submit" value="Nyast först" id="sort_asc" />
</form>
<script>
$('#sort_desc').click(function(){
$('#sorting').val('desc');
});
$('#sort_asc').click(function(){
$('#sorting').val('asc');
});
</script>
I think its not possible. A form is used to send data (mostly) via POST or GET. Your goal is to open a specific URL. I would create a standard and would style it like a button. Whats the reason you want to use a button?

Submit form with a link and include a name value

I want to replace the form button
<input type="submit" name="submitForm" value="Send" />
with a link.
What I have at the moment is:
Send message
But I need include the name="submitForm" somehow.
Thanks for your help.
You can create a hidden input in your form:
<input type="hidden" name="submitForm" value="submitForm" />
What you can do is to use data-attribute ...
Send message
Then you can retrieve the name by ...
$(this).attr('data-name');

how to pass textbox value to next jsp page by clicking on a different form button without using javascript

here is my code
<body>
<input type=text name=name>
<form action=new3.jsp method=post name="f1">
<input type=text name=name>
<input type=submit value=next>
</form>
<form action=new1.jsp method=post>
<input type=submit value=back>
</form>
</body>
as you can see there are two forms here with two different submit buttons named "next" and "back". The text box is in the form where "next" button is. My question is here how to send the value of this text box to "new1.jsp" clicking "back button" without using javascript. Thanks in advance...
Don't post form to JSPs. Post the to servlets instead, and let the server analyze the parameters and forward to the appropriate JSP depending on which button has been clicked:
<form action="/controllerServlet" method="post" name="f1">
<input type="text" name="name"/>
<input type="submit" name="destination" value="next"/>
<input type="submit" name="destination" value="back"/>
</form>
Using the above form (which BTW, is valid HTML), the servlet can use the value of the "destination" parameter. If it's "next", it should forward to new3.jsp. If it's back, it should forward to "new1.jsp". And if, for example, you want to redisplay the same page because the user didn't enter a valid value in the text field, it can do so.
That's the well-known MVC pattern. You should use it.

how use button in internet explorer?

on my source i use
<a href='pag.php'><input type='button' value='Next'/></a>
in firefox and crome when i click on the button i'm redirected to pag.php
but in ie it don't work. how can i do?
The simple way is:
<input type='button' value='Next' onclick="location.href='pag.php'"/>
Form buttons are meant to be used for submitting a form to the page specified in the action attribute, not to be wrapped in <a> tags, which is bad syntax. If this is for a multi-part form, simply add the action attribute to the <form> tag like
<form method="POST" action="pag.php">
<!-- your form elements -->
<input type="submit" value="Next">
</form>
And that will submit the form to pag.php. Otherwise, just use a link, or, if you insist on having it look like a button, use an image link like:
<img src="image_that_looks_like_a_button.png">
Hope this helps.
Instead of what you are doing right now, go for:
<form action="pag.php" method="post" enctype="multipart/form-data">
<INPUT TYPE="submit" name="Submit" value="Next">
</form>
But if you want image instead in place of button, go for:
<INPUT TYPE="image" SRC="image location" ALT="Next">
Hope it solves your problem! :)