Currently I am working on one form which contains 2 buttons. Clicking on 1 button I am getting block of html fields as below.
`
<table width="100%">
<tbody><tr>
<td class="style4" width="12%" align="center">CODE<span class="style3"> </span></td>
<td width="18%"><input name="c_code[]" value="" id="c_code__" class="box_border" style="width: 120px;" type="text"></td>
<td class="style3" width="15%" align="right">Price</td>
<td width="7%"><input name="c_price[]" value="" id="c_price__" class="box_border" style="width: 40px;" type="text"></td>
<td class="style3" width="4%" align="right">Qty</td>
<td width="7%"><input name="c_qty[]" value="" id="c_qty__" class="box_border" style="width: 40px;" type="text"></td>
<td class="style3" width="9%" align="right">On Sale </td>
<td width="3%"><input name="c_onsale[]" id="c_onsale__" value="" type="radio">
<label for="c_onsale"></label>
</td>
<td class="style3" width="10%" align="center">Exposition</td>
<td width="15%"><input name="c_exposition[]" size="15" value="" id="c_exposition__" class="box_border" type="text"></td>
</tr>
</tbody></table>
`
Now each time user clicks on button whole block given above will be included in html form using ajax method call.
Now my problem is how can I get values of all elements as an array in struts2 action class.
Or How to write setter and getter method for these arrays.
Is there any better way to perform above in other way which make work easier for me?
How to write struts2 validation file for array fields like this?
Can anyone help me in this matter.
Thanks.
Ok, if you can rename your fields using an index in the array for each iteration, so they'll be named c_name[0], c_name[1], etc... Then you can just define an array in your action class and the mapping will be done without problems.
As for validation I would suggest a server-side validation on your action.
Regards,
Use List instead of an array on the server side and struts will automatically map the new sections(new block of element on UI) to it.
If you define it as an array then it will not be able to initialize new section each time as the size cannot increase dynamically
Related
I have this code below from HTML document, result of inspection object from site web.
I want to get the object <input name="username" value=""> with VBA Excel code.
<tr id="username_block">
<td class="shade" width="50%" align="right">
<div align="left">Nom d’utilisateur:</div>
</td>
<td class="shade" width="50%">
<input name="username" value="">
</td>
</tr>
I use this instruction
set element=oIe.Document.getElementsById("username_block")
but no results (element=nothing).
Isn't the method's name getElementById, without "s"?
I am setting up a new website through godaddy.com and am having the hardest time trying to code up the calculator for customers to estimate their payments (Must Include: Loan Amount, Loan Length in Months, Interest rate, and Monthly Payment). The Monthly payment is what I am having trouble calculating because of code placement. Again, i am working with godaddy.com and just need an HTML code for this payment estimator.
I have tried inspecting multiple pages to see what I can get off of them, I have used an html generator, and have contacted several people in my are with no hope.
This is the code I currently have:
<html><div class="wpb_wrapper"><center><form method="POST" name="calc">
<table border="0" width="60%">
<tbody>
<tr>
<th bgcolor="#FFFFFF" width="50%">Data Entry</th>
</tr>
<tr>
<td bgcolor="#F7F7F7">Loan Amount</td>
<td align="right" bgcolor="#F7F7F7">$<input id="amount" max="100000000" min="1" name="loan" size="10" type="text" /></td>
</tr>
<tr>
<td bgcolor="#F7F7F7">Loan Length in Months</td>
<td align="right" bgcolor="#F7F7F7"><input name=" months" size="10" type="text" /></td>
</tr>
<tr>
<td bgcolor="#F7F7F7">Interest Rate</td>
<td align="right" bgcolor="#F7F7F7">%<input max="10000000" min="1" name="rate" size="10" type="text" value="10" /></td>
</tr>
<tr>
<td bgcolor="#F7F7F7">Monthly Payment</td>
<td align="right" bgcolor="#F7F7F7"><em>Calculated</em> <input name="pay" size="10" type="text" /></td>
</tr>
<tr>
<td align="center" bgcolor="#FFFFFF"><input type="reset" value="Reset" /></td>
<td align="center" bgcolor="#FFFFFF"><input type="button" value="Calculate" /></td>
</tr>
</tbody>
</table>
</form>
<p><span style="font-size: xx-small;"> "Enter only numeric values (no commas), using decimal points where needed." <br /> "Non-numeric values will cause errors." </span></p>
</center></div></html>
No error messages, it just won't let me calculate the monthly payment.
What you have is a pure HTML code, which cannot do any calculation by itself.
However, if all you want is a simple loan calculator, you don't have to code one from scratch. There are free ready-to-use calculators available that can be embedded in to your HTML code.
Solution 1: Using an HTML embed code.
Here's one such free calculator I found from https://www.mortgagecalculator.biz/c/free3.php :
Paste this in your html code:
<div style="width:185px; text-align:center;">
<p style="text-align:center;">
<a href="https://www.mortgagecalculator.biz" target="_blank">
<img src="https://www.mortgagecalculator.biz/img/mlogo.gif" border="0" alt="Mortgage Calculator.biz."/>
</a><br/>
<iframe src="https://www.mortgagecalculator.biz/c/variables.php?loan=258678&rate=4.1&years=30" frameborder="0" width="185px" height="240px" scrolling="no"></iframe><br/>
<font size="1" color="#000000">HTML Mortgage Calculators</font>
</p>
</div>
The downside of using an embed code is it relies on an external site for the calculator. If that site goes down, so does your calculator.
Solution 2: Integrating code in the html file:
The better alternative is to integrate the actual calculator code on your HTML file. Try looking for a free code online, that can be used with the author's permission.
Here is something for your reference: http://www.javascriptkit.com/script/cut155.shtml
PS: Posting this as an answer since my current reputation (11) doesn't let me comment.
HTML alone can't do calculations. To do this, you will need to learn javascript (there are many good tutorials on the web).
After you learn javascript, and you know how to create functions and change the content of elements, you can do these calculations.
To run a javascript function when a button is clicked, write this:
<button onclick="function();">Button text</button>
I've written probably a dozen forms for this project but for some reason this ONE is not working. I can't discern any difference between it and any of my other forms.
By not working, I mean the page does not redirect when the submit button is clicked.
Also, the default value I try to put in the 'patient' field isn't appearing but that's not important.
It's probably something really silly like an unbalanced tag or something but I just cannot find it. Can a pair of fresh eyes help me out?
<form id='addBill' method='POST' action="/add_to_bill.php">
<table class='t' style='width:100%'>
<tr>
<td class='tt'><p>Patient ID</p></td>
<td class='tt'><input disabled class='t' type="numeric" name="patient" value=<?php getP('id') ?>></td>
<td class='tt'><p>Visit ID</p></td>
<td class='tt'><input class='t' type="numeric" name="visit"></td>
</tr>
<tr>
<td class='tt'><p>Invoice Number</p></td>
<td class='tt'><input class='t' type="numeric" name="invoice"></td>
<td class='tt'><p class='t'>Due Date: (format: e.g. <?php echo "'".date('Y-m-d')."'"; ?>)</p></td>
<td class='tt'><input class='t' type="text" name="date" value=<?php echo "'".date('Y-m-d')."'"?>></td>
</tr>
<tr>
<td class='tt'><input class='t' type="submit" value="Go"></td>
</tr>
</table>
</form>
based on the image of the code i noticed there is a form tag without the closed form tag. there are two form tag in it, one without closed form tag which is at most top of the code and another one is at bottom
I read several articles, but couldn't really get things working. Here's what I'm talking about. The Html of a webpage:
<form id="LOGINFORM" name="LOGINFORM" style="margin:0px; padding:0px;" action="login.php" method="post">
<table cellspacing="2" cellpadding="0" border="0" width="100%">
<tr>
<td width="100" align="center" valign="bottom">
Username:
</td>
<td width="100" align="center" valign="bottom">
Pass:
</td>
<td valign="top" align="right">
</td>
</tr>
<tr>
<td align="center">
<input class="inputbox" style="text-align:center; width:90px;" maxlength="12" name="loginname" type="text" size="12">
</td>
<td align="center">
<input class="inputbox" style="text-align:center; width:90px;" maxlength="12" name="password" type="password" size="12">
</td>
<td align="left">
<input
class="button_ok"
name="btnSubmit"
id="btnSubmit"
type="submit"
value="Вход"
onclick=""
>
</td>
</tr>
</table>
</form>
say the webpage is helloworld.com, account is foo, pass is bar.
What I browse: helloworld.com/login.php?loginname=foo&password=bar
But server returns that username/password is wrong, but they aren't. What do I do wrong?
The logic in login.php says that loginname=foo&password=bar is wrong. That is where you need to look to find out why it doesn't work.
As for what is wrong with the HTML.
You are using a table for layout
You aren't using <label> elements to label your inputs
You having given a form a name, these days an id is all that is required (and then only if you need to reference it with JS or CSS)
You are using a style attribute instead of a seperate stylesheet, and quite a few obsolete presentational attributes (such as align, width and cellspacing)
that form secifies that the data is passed via POSt, and not GET as you are trying to pass it. If a form wants data back specifically as POST data, that page will ignore GET data. see this tutorial
Your HTML says method="post", so I guess the server will only accept those values by the POST method. When you browse that URL, you are sending them using the GET method.
You are confusing GET and POST in PHP:
$_GET['loginname'] will retrieve a query string variable.
$_POST['loginname'] will retrieve the value of the input named "loginname". (This is what you need.)
helloworld.com/login.php?loginname=foo&password=bar uses GET
In my jsp code I use the request.getParameter() to retrieve the data which is entered in html. The data was retrieved when using get method but it is not when im using post method
Why this happend
My html form is
<code>
<form name="inp" action="upload.jsp" method="post" onsubmit="return valid();" enctype="multipart/form-data">
<table align="center" cellspacing="2">
<tr><td></td></tr>
<tr><td></td></tr>
<tr><td></td></tr>
<tr><td><font size="5" color="#E41B17">Select File</font> </td>
<td><input type="file" name="infile"></td>
</tr>
<tr><td><font size="5" color="#E41B17">Target File Name</font></td>
<td><input type="text" size="20" name="filename"></input></td>
</tr>
<tr></tr>
<tr><td colspan="2" align="center"><input type=submit value="Upload" ></td></tr>
</table>
<br></br>
<center>
<font color="#E41B17">HOME</font>
</center>
</form>
</code>
And my jsp scriptlet is
<% String f = request.getParameter("filename");
System.out.println(f); %>
Thanks in Advance
Now to the issues: you've set the form's content type to be multipart, which means that you have to explicitly parse the request body; the container will only parse if you leave the default form-encoded. This article seems to give an example of how to access multipart data on the server side.
Aside from that, you do realize that your form is commented-out, so should never be handled by your browser, right? If you're actually seeing something on the browser, it probably isn't coming from this location.