I have a big form in PHP with several tables, each of one calculates a sum (of price and quantity) and then there's one at the end that calculates the total.
The structure is, more or less, this:
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" id="purchase_form">
<div id="purchase_1">
<table>
<input id="price_1">
<input id="quantity_1">
<input type="submit" name="calculate" value="Click here to calculate the partial">
</table>
</div>
<div id="purchase_2">
<table>
<input id="price_2">
<input id="quantity_2">
<input type="submit" name="calculate" value="Click here to calculate the partial">
</table>
</div>
<tr>
<td id="price_sum"><?php *script* ?></td>
<td id="quantity_sum"><?php *script* ?></td>
</tr>
</form>
Now, when I click on submit to calculate the "partial", it gives me the total, at the same time. I know it's not a state-of-the-art form, but anyway, just try to turn a blind eye on that.
What I want is, when I click on submit button, to have the page reloaded showing the form I have clicked on. Like, if I click on submit of the #purchase_1 table, I want the page to reload on #purchase_1 table, and so on.
Is it possible to do that with javascript?
Related
I have a webpage with three buttons, two of the buttons action the form submitting data to the server, it then sends back the appropriate page.
The third button is meant to just open a new webpage in a new tab, the current page does not need to be reloaded so this button is just a button element with some onclick() code, its is not part of an input element
The trouble is that when I click on the third button it actions the form action the form even though its not an input type, why does it do this ?
<main>
<form action="/license.process" name="process" id="process" method="post">
<label>
Please enter your license information as provided in your license email
</label>
<table>
<tr>
<td><label title="Email">Email</label></td><td><input type="text" name="licenseEmail" value="paultaylor#jthink.net" class="licenseinputfield"></td>
</tr>
<tr>
<td>
<label title="License Key 1">
License Key 1
</label>
</td>
<td>
<input type="text" name="licenseKey1" value="50302c02147f23ed809a8f2579338121a2b1594f967bb18" class="licenseinputfield">
</td>
</tr>
<tr>
<td>
<label title="License Key 2">
License Key 2
</label>
</td>
<td>
<input type="text" name="licenseKey2" value="0ff02146cd1777d7e0890e659b10218761869212d7b0d60" class="licenseinputfield">
</td>
</tr>
</table>
<input type="submit" name="cancel" value="Cancel">
<input type="submit" name="save" value="Save">
<button onclick="window.open('http://www.jthink.net/songkong/buy.jsp','_blank');">
Get License
</button>
</form>
</main>
I can make it work properly by moving this third button outside of the form. But then I get formatting problem because button is shown on next line, regardless I want to understand why having the butto within the form triggers the form.
The default type of a <button> is submit.
If you want it to be type=button then you have to say so explicitly.
You need to add the type="button" attribute to prevent the form from being submitted.
I'm not entirely sure why but came across this last week.
In this piece of code there is a search bar, when I am searching something it will narrow down my search. I am using onkeyup event which call javascript function to search the required data, but after entering some text in search bar when i press enter it is redirecting to the home page instead of display the results.
CODE
<apex:actionFunction name="searchServer" action="{!runSearch}" rerender="results,debug,errors">
<apex:param name="Name" value="" />
</apex:actionFunction>
<table cellpadding="2" cellspacing="2">
<tr>
<!-- style="font-weight:bold;">Defect Name<br/> -->
<td>
<input type="text" id="Name" onkeyup="doSearch();" /> </td>
</tr>
</table>
Any help would be appreciated.
I think the form is submitted on Enter button press.
If you have <apex:form tag then try putting onsubmit="return false;" there.
<apex:form onsubmit="return false;"
I have four files, they are index.php, commonform.php, image1.php, image2.php
Suppose, in the index.php I have a form with two image input, the form's action change dynamically, method is post. when the first image is clicked is goes to commonform.php and also when the second image is clicked is goes to commonform.php but in commonform I have a form with some button input (its work can be anything and not my concern) and a submit button. My concern is when the first image is clicked, it goes to commonform.php and when the submit button is clicked of commonform.php, it goes to image1.php and same things for when the second image is clicked, it goes to commonform.php and when the submit button is clicked of commonform.php, it goes to image2.php. Can anyone help me?
You may attach a variable to your requests in index.php and then recognize it in commonform.php and decide to jump to the target destination !
For Example :
index.php
<form action="commonform.php" method="POST">
<input type="image" name="image_1" src="image1.gif" alt="Image 1">
<input type="image" name="image_2" src="image2.gif" alt="Image 2">
</form>
commonform.php
<?php
if (isset($_POST['image_1_x'], $_POST['image_1_y'])) {
$action = 'image1.php';
}
if (isset($_POST['image_2_x'], $_POST['image_2_y'])) {
$action = 'image2.php';
}
?>
<form id="commonform" action="<?php echo $action; ?>" method="POST">
<input type="button" value="From HTML">
<input type="button" value="Content">
<input type="button" value="Button style ">
<br><br>
<input type="submit" name="submit" value="Submit">
</form>
when you are processing the INPUT with IMAGE type artibute ; it sends the X , Y artibutes , we just need to check them !
I want to ask you guys how i can put a form method "Get" in a table. In my table i have got a text field and when i submit this form it will check for validation. My validation works fine but this form doest actually submit it as i don't aget any values at the URL.
<form method="GET" id="my_form">
<table>
<tr>
<td>
<input type="submit" name="submit" id="submit" value="submit" onclick="return submitvalidation();" form="contactusform">
</td>
</tr>
</table>
</form>
Your submit button belongs to a different form.
Remove
form="contactusform"
I am facing a problem. I have created a form where a user has to input the details about a candidate and also upload his/her image. The problem is that in the form there is a button that says "Click To Add More Candidate", so when this button is clicked the same form should reappear under a division called "moreCandidates". Now to achieve this how should I go about it? Things that are coming in my mind is as follows:
To create a function in javascript that exactly creates the form contents (ie. all the input fields,etc) and onclick of the button "Click To Add More Candidate", call the function under the mentioned division. I can do this as in the past I have done something very similar to this. However, this time I don't think it would be good idea to create the whole form again as I have written a PHP function in between to read a directory.
Or the second thought that I have is to have the form code written in a file called candidate.php and call that file with AJAX. The problem here could be that I might be calling the whole form again (whereas I just want to call the contents of the form like the candidate name, and other stuff)
I very confused at the moment, and help from you all would be greatly appreciated. Thanks in advance.
My html code:
<div id="candidateForm">
<table border="0">
<form method="post" action="formDetails.php" enctype="multipart/form-date">
<tr>
<td>Candidate Name:</td>
<td><input class="candidateForm" type="textbox" name="candidateName" placeholder="Candidate's Name"/></td>
</tr>
<tr>
<td>Enroll No:</td>
<td><input class="candidateForm" type="textbox" name="enrollNumber" placeholder="Enroll No"/></td>
</tr>
<tr>
<td>Candidate Image:</td>
<td><input class="candidateForm" type="file" name="candidateImage" placeholder="Select a Image"/></td>
</tr>
<tr>
<td>Cadidate Post:</td>
<?php
//This is the target folder that is going to be read.
$target="uploads/";
//I an using a directory function in PHP scandir() which scans tha contains of the give directory
$dir=scandir($target);
?>
<td>
<select name="candidatePost">
<option value="candidatePost" select="selected">---------Select---------</option>
<?php
foreach($dir as $folders)
{
//When we loop throung the target folder/directory we get this annoying two folder that is "." and ".." so just to rule then out i m using an IF condition
if($folders!="."&& $folders!="..")
//echo $folders;
echo "<option class='candidateForm' value=$folders>$folders</option>";
}
?>
</select>
</td>
</tr>
<tr>
<td>About The Candidate:</td>
<td><textarea name="aboutCandidate" cols="40" rows="5"></textarea></td>
</tr>
<div id="moreCandidates"> </div>
<tr>
<td></td>
<td><input type="button" value="Click To Add More Candidate"></input> </td>
</tr>
<tr>
<td></td>
<td><input type="submit" name="candidateFormSubmit" value="Press Here To Submit The Details" onclick=""/></td>
</tr>
</form>
</table>
</div>