This code has two links with same name but different values. If i click first link, i want to get value 10. Is it possible using javascript with link submit()??
<form name="listpages" action="page.php" method="post">
<input type="hidden" name="pgnum" value="10">
<input type="hidden" name="pgnum" value="20">
</form>
thanks in advance
No. But you can use this code to achieve the desired results.:
<form name="listpages" action="page.php" method="post">
<input type="submit" name="pgnum" value="10">
<input type="submit" name="pgnum" value="20">
</form>
EDIT
The JavaScript way. I don't see why you want to stick to JS. Your code will be broken when a user has disabled JavaScript (by using NoScript, for example);
<form name="listpages" action="page.php" method="post">
<input type="hidden" id="pgnum1" value="10">
Option 1
<input type="hidden" id="pgnum2" value="20">
Option 2
</form>
Why not use a single hidden input and set it's value via the hyperlink:
<form name="listpages" action="page.php" method="post">
<input type="hidden" name="pgnum" value="10">
10
20
</form>
You could use a single form and combine it with some javascript code to submit the form with the appropriate page number:
<form name="listpages" action="page.php" method="post">
<input type="hidden" name="pgnum" value="1">
</form>
<script type="text/javascript">
function submitPageForm(pageNo) {
var form = document.forms.namedItem("listpages");
form.elements.namedItem("pgnum").value = pageNo;
form.submit();
}
</script>
...
But be reminded that for websites it is actually recommended to use GET parameters to switch pages, content items etc.
Here is a very good guide on choosing between GET and POST: http://www.w3.org/2001/tag/doc/whenToUseGet.html
Finally, if you decide to switch to GET, you no more need the form at all. I.e. you can simply write:
...
Related
I have a html form with input fields that require a value before submission and to achieve this I am using the required attribute in html5 Which is shown in the snippet below with the header Form One.
The problem is I'd like to add a confirm pop-up message after the delete button is clicked -- asking if the user wants to continue.
I have done this in the snippet shown below with the header Form Two but the problem is, the required attribute is not showing when the input field is empty and submitted.
The form gets submitted before the required method is triggered. Anyone has any ideas to solve this html5 incompetence?
THANKS
<h2>Form One </h2>
<form method="post" action="example.com" id="delete_page">
Name : <input type="name" required><br>
<input type="button" value="Cancel">
<input type="submit" value="Delete">
</form>
<hr>
<h2>Form Two </h2>
<form method="post" action="example.com" id="delete_page">
Name : <input type="name" required><br>
<input type="button" value="Cancel">
<input type="submit" onclick="confirm('Are you sure you want to submit')" value="Delete">
</form>
Try using onsubmit on your <form> rather than the button.
<h2>Form Two </h2>
<form method="post" action="example.com" id="delete_page"
onsubmit="return confirm('Are you sure you want to submit?')">
Name : <input type="name" required><br>
<input type="button" value="Cancel">
<input type="submit" value="Delete">
</form>
Browser form validation only kicks in on a submit event.
This will also prevent your form from submitting if the user chooses to "Cancel" the popup.
After making a request to URL I get a HTML page as a response.THe responded page consists of a form of whose variable I want to fetch.
Output
<input type="hidden" name="Flag_CustomerStatus" value="1">
<input type="hidden" name="Flag_InstantPayment" value="" />
<input type="hidden" name="txtMerchNum" value="90">
<input type="hidden" name="txtHttp" value="http://www.mywebsite.com/ThankYouPage.php">
<input type="hidden" name="txtMerchRequest" value="add_cc">
<input type="hidden" name="action" value="">
<input type="hidden" name="IsPostBack" value="True">
<input type="hidden" name="Lng" value="en">
I am familiar with Php and I can extract these variables using $_POST['Flag_CustomerStatus'] but I am not able to parse them when implemmenting in Node Js.
Kindly suggest
after you get success ajax result - you can write this html to other div
like this
<div style='display:none;' id='hidden_div'>
....
....
$('#hidden_div').html(your_html);
after it you can choice any value by JQuery from any hidden input
Or second solution is - you can change php side
and get array with values, after it - you can generate HTML
I have two forms on my page...
<form method="post" action="">
<input type="text" name="name" id="name"/>
<input type="submit" name="form1_submit_pushed"/>
</form>
<form method="post" action="">
<input type="submit" name="form2_submit_pushed/>
</form>
On my php side I want to be able to know the value of the text input "name" when I push the submit button of the second form. Kind of like....
if(isset($_POST['form2_submit_pushed']))
{
echo $_POST['name']; //or something else?
}
The reason behind is that first form has a bunch of data that I don't want in the second form submission.
You could do something like this...this code uses jQuery:
<form id="form1" method="post" action="">
<input type="text" name="name" id="name"/>
<input type="submit" name="form1_submit_pushed"/>
<input type="hidden" name="form2_submit_pushed" id="form2_submit_pushed">
</form>
<form id="form2" method="post" action="">
<input type="submit" name="form2_submit_pushed"/>
</form>
<script>
$('#form2').submit(function(event) {
//prevent form2 from submitting and submit form1 instead...
event.preventDefault();
//before submitting, indicate that the "form2_submit_pushed" button was pushed
$('#form2_submit_pushed').val(true);
//submit form1
$('#form1').submit();
});
</script>
...but why you would want to I don't know. Why not make all the controls part of the same form? HTML is designed to send info from only one form (at a time) to the server...
UPDATE: Sorry, I didn't notice your line where you explain your reason for wanting to do this. If you want more explicit control over what gets sent to the server I recommend using AJAX to submit the form. Look at https://api.jquery.com/serializeArray/ and https://api.jquery.com/jQuery.ajax/
Correct me if I am wrong here, but I beleive normal HTML will only post the inputs from the form you are posting from. One option would be to have a hidden input on the second form which gets updated via javascript during the input's change event.
So, you could do something like this (I don't recommend inline javascript but it should get you in the right direction):
<form method="post" action="">
<input type="text" name="name" id="name" onchange="document.getElementById('hiddenname').value=this.value"/>
<input type="submit" name="form1_submit_pushed"/>
</form>
<form method="post" action="">
<input type="hidden" name="hiddenname" id="hiddenname"/>
<input type="submit" name="form2_submit_pushed/>
</form>
Then you just need to get it using
$_POST['hiddenname'];
I tried to do auto form submission.It works fine and it redirected to the action page.But,it does not carry the values.Please help me to find the solution.
<form method="POST" action="SamplePage" name="myForm" id="formone">
<input type="hidden" name="AMT" value="10"/>
<input type="hidden" name="ID" id="cust"/>
<input type="submit" value="Submit" id="bu" name="i"/>
</form>
I used document.getElementById("formone").submit(); the for auto submission.
Try like this
document.forms["formone"].submit();
or you can try like
document.formone.submit();
Where your form name should be formone
And at your action page try to access the REQUEST values
print_r($_REQUEST);
I have a form like so:
<form method="post" action="task.cfm" name="lookup" id="lookup">
<input type="hidden" name="action" value="">
<input type="hidden" name="emailAddress" value="">
</form>
And I'm posting to this form using this link:
View User details
The link works, but I'm trying to get it to open in a new window. target="_blank" does not work in this case. Any help would be appreciated.
Add the target attribute to your form:
<form method="post" action="task.cfm" name="lookup" id="lookup" target="_blank">
<input type="hidden" name="action" value="">
<input type="hidden" name="emailAddress" value="">
</form>
Did you place the target="_blank" attribute on the anchor, or on the form tag? Try placing it on the form tag.