I want to jump between textfields, but these fields are generated dynamically through an iterator from struts-tags:
<s:iterator value="aList">
<td width="50px" align="center">
<s:textfield name="solField" size="2" maxlength="1" style="text-transform: uppercase; text-align:center"/>
</td>
</s:iterator>
I tried jumping with javascript but having the same field name is not working properly.
The code in the browser is (with three items in the list to iterate):
<td width="50px" align="center">
<input type="text" name="solField" size="2" maxlength="1" value="" id="correct_solField" style="text-transform: uppercase; text-align:center"/>
</td>
<td width="50px" align="center">
<input type="text" name="solField" size="2" maxlength="1" value="" id="correct_solField" style="text-transform: uppercase; text-align:center"/>
</td>
<td width="50px" align="center">
<input type="text" name="solField" size="2" maxlength="1" value="" id="correct_solField" style="text-transform: uppercase; text-align:center"/>
</td>
Any ideas?
Thanks in advance
How about this? (using jQuery)
$(document).on('keyup', 'input', function(){
if($(this).val().length >= $(this).attr('maxlength'))
{
$(this).nextAll('input:first').focus();
// OR even
// $(this).next('input').focus();
}
});
Is that what you're looking for? http://fiddle.jshell.net/C3jeY/
Related
<div id="rightContent" style="display: inline-block; width: 700px; vertical-align: top;">
<div>
<h1><em class="SomethingHeading">Something</em></h1>
</div>
<div class="content scaffold-list" role="main">
<h1>Search</h1>
<form action="/SomethingArchiveUI/search/search" method="post">
<table>
<tbody>
<tr>
<td>ID/Registration Number:</td>
<td>
<**input type="text" name="idNumber" maxlength="20" value="" id="idNumber"**>
</td>
</tr>
<tr>
<td>Client Name:</td>
<td>
<input type="text" name="clientName" maxlength="50" value="" id="clientName">
</td>
</tr>
<tr>
<td>Client Surname:</td>
<td>
<input type="text" name="clientSurname" maxlength="50" value="" id="clientSurname">
</td>
</tr>
<tr>
<td colspan="2">
<input type="hidden" name="_dateRange"><input type="checkbox" name="dateRange" value="true" id="dateRange"><label for="dateRange"> Use date range?</label>
</td>
</tr>
<tr>
<td colspan="2"><p>From: <input type="text" name="fromDate" value="" maxlength="10" id="fromDate" class="hasDatepicker"> To: <input type="text" name="toDate" value="" maxlength="10" id="toDate" class="hasDatepicker"></p></td>
</tr>
</tbody>
</table>
<div style="display: inline;">
<div id="divSubmit">
<input type="submit" name="cmdSearch" class="buttons" value="Search" id="cmdSearch">
</div>
<div id="divBusy" style="display: none;">
Busy Searching...
</div>
</div>
</form>
<table id="customerIdentificationList" style="display: block;">
</table>
<div id="loadingMessage" style="display: none;">
Loading. Please wait.
</div>
</div>
</div>
I used this code below for logging into the Application, but similar code doesn't seem to work on this form above. I'm trying to find the 'idNumber' element:
driver.findElement(By.xpath("//*[#id='idnumber']")).sendKeys("Username");
driver.findElement(By.xpath("//*[#id=\'password\']")).sendKeys("Password");
driver.findElement(By.xpath("//*[#id=\'submit\']")).click();
The error i get is: org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"xpath","selector":
Looking forward to your responses.
Use : .//input[#id='idnumber']
Why not just use By.id()?
driver.findElement(By.id("idNumber"));
I don't know the reason why you can't use By.id() or By.xpath in this case. But you can try to find the input using text in previous td. I hope next code will help:
driver.findElement(By.xpath("//td[text()='ID/Registration Number:']/following-sibling::td/input")).sendKeys("Username");
Try using the below way -
First get the root element and keep it to a WebElement object. Then find for input element idNumber
WebElement elem = driver.findElement(By.cssSelector("#rightContent > div.content.scaffold-list > form"));
elem.findElement(By.id("idNumber")).sendKeys("Username");
Please have a look at the below code:
<table border="0" width="100%" id="id1">
<tr>
<td width="15%" nowrap>
<Label class="someClass"> Testing </Label>
</td>
//Error complaining at below line
<td width="30%" class="someClass" nowrap>
<html-el:text styleClass="Test" property="someProperty" size="30" maxlength="10"/>
</td>
</tr>
</table>
For the first td I've closed it but at the second td it's complaining IWAK0061E Start tag() not closed.
May I know what's wrong?
I don't know why you use such weird html syntax ,however I would use:
<table border="0" width="100%" id="id1">
<tr>
<td width="15%">
<Label class="some class"> Testing </Label>
</td>
<td width="30%" class="some class">
<textarea property="some property" maxlength="10" class="some class"></textarea> // all visual stuff is used with class tag
<input property="some property" maxlength="10" class="some class"> // or input with one line field
</td>
</tr>
</table>
Also, nowrap attribute is not supported in HTML5. Use CSS instead.
I have below mentioned code in JSP Page. I am able to save all the values from below text boxes to DB. However, I read each text box name in my servlet (request.getParameter()) to save the fields. Is it possible to improve this code? like for example : to save all the values of one particular column in an array and save to db. If yes; please show an example that helps me. Also how to ignore if a row is empty. for example, user fills only two rows and rest rows are empty. I want to save only first two rows in DB.
<table class="cmn-table" id="t1" border="1" style="margin-left: 0.2em; margin- right:0em">
<col width="5%">
<col width="18%">
<col width="18%">
<col width="18%">
<col width="18%">
<col width="18%">
<tr>
<th>Sl.No</th>
<th>Source IP Address</th>
<th>Destination IP Address</th>
<th>Service and Port (TCP, UDP, etc.)</th>
<th>Start Date</th>
<th>Expiration Date</th>
</tr>
<tr>
<td style="align:center"> 1 </td>
<td><input type="text" name="name" id="name" size="20"> </td>
<td><input type="text" name="name1" id="name1" size="20"> </td>
<td><input type="text" name="name2" id="name2" size="20"> </td>
<td><input type="text" name="name3" id="name3" size="15"> <img src="../Image/cal.gif" id="" style="cursor: pointer;" onclick="javascript:NewCssCal('name3','MMddyyyy','dropdown',false,'12')" /></td>
<td><input type="text" name="name4" id="name4" size="15"><img src="../Image/cal.gif" id="" style="cursor: pointer;" onclick="javascript:NewCssCal('name4','MMddyyyy','dropdown',false,'12')" /> </td>
</tr>
<tr>
<td style="align:center"> <label> 2 </label> </td>
<td><input type="text" name="name5" id="name" size="20"> </td>
<td><input type="text" name="name6" id="name" size="20"> </td>
<td><input type="text" name="name7" id="name" size="20"> </td>
<td><input type="text" name="name8" id="name3" size="15"> <img src="../Image/cal.gif" id="" style="cursor: pointer;" onclick="javascript:NewCssCal('name3','MMddyyyy','dropdown',false,'12')" /></td>
<td><input type="text" name="name9" id="name4" size="15"><img src="../Image/cal.gif" id="" style="cursor: pointer;" onclick="javascript:NewCssCal('name4','MMddyyyy','dropdown',false,'12')" /> </td>
</tr>
<tr>
<td> <label> 3 </label> </td>
<td><input type="text" name="name10" id="name" size="20"> </td>
<td><input type="text" name="name11" id="name" size="20"> </td>
<td><input type="text" name="name12" id="name" size="20"> </td>
<td><input type="text" name="name13" id="name3" size="15"> <img src="../Image/cal.gif" id="" style="cursor: pointer;" onclick="javascript:NewCssCal('name3','MMddyyyy','dropdown',false,'12')" /></td>
<td><input type="text" name="name14" id="name4" size="15"><img src="../Image/cal.gif" id="" style="cursor: pointer;" onclick="javascript:NewCssCal('name4','MMddyyyy','dropdown',false,'12')" /> </td>
</tr>
<tr>
<td> <label>4 </label> </td>
<td><input type="text" name="name15" id="name" size="20"> </td>
<td><input type="text" name="name16" id="name" size="20"> </td>
<td><input type="text" name="name17" id="name" size="20"> </td>
<td><input type="text" name="name18" id="name3" size="15"> <img src="../Image/cal.gif" id="" style="cursor: pointer;" onclick="javascript:NewCssCal('name3','MMddyyyy','dropdown',false,'12')" /></td>
<td><input type="text" name="name19" id="name4" size="15"><img src="../Image/cal.gif" id="" style="cursor: pointer;" onclick="javascript:NewCssCal('name4','MMddyyyy','dropdown',false,'12')" /> </td>
</tr>
<tr>
<td> <label>5 </label> </td>
<td><input type="text" name="name20" id="name" size="20"> </td>
<td><input type="text" name="name21" id="name" size="20"> </td>
<td><input type="text" name="name22" id="name" size="20"> </td>
<td><input type="text" name="name23" id="name3" size="15"> <img src="../Image/cal.gif" id="" style="cursor: pointer;" onclick="javascript:NewCssCal('name3','MMddyyyy','dropdown',false,'12')" /></td>
<td><input type="text" name="name24" id="name4" size="15"><img src="../Image/cal.gif" id="" style="cursor: pointer;" onclick="javascript:NewCssCal('name4','MMddyyyy','dropdown',false,'12')" /> </td>
</tr>
</table>
As much as i understand, you want to get rid of calling request.getParameter on all the input fields.
Why dont you use below:
request.getParameterMap()
This gives you a map of all the parameter names and values. So, you can iterate through the map and keys in the map are parameter names and value for that key is/are the values for that parameter. Its a simple iteration over map. While iterating through the map, you can actually prepare your DB query as well based on other checks like null check.
I'm trying to connect to a URL with a form that has this values:
http://aulavirtual.uv.es/
How can I do this if every time I log value changes (time, token_id, hash) ? Please, help me !! I try with HttpUrlConnection and now with HttpClient 4.
<form name="login" method="post" action="/register/">
<input type="hidden" name="form:mode" value="edit">
<input type="hidden" name="form:id" value="login">
<input type="hidden" name="__confirmed_p" value="0">
<input type="hidden" name="__refreshing_p" value="0">
<input type="hidden" name="return_url" value="/dotlrn/index">
<input type="hidden" name="time" value="1352222384">
<input type="hidden" name="token_id" value="423">
<input type="hidden" name="hash" value="3F8865DB5E6603C296428A5A7C0D66C0256D5626">
<tr>
<td class="formulari">Nom d'usuari</td>
<td class="formulari">
<input type="text" id="username" name="username" value="" size="25" alt="Nom d'usuari"></td>
</tr>
<tr>
<TD class="formulari">Contrasenya</TD>
<TD class="formulari">
<input type="password" id="password" name="password" size="25" ALT="Contrasenya d'accés"></TD>
</tr>
<TR>
<TD COLSPAN="2" class="formulari1">
<div align="center">
<input id="login" type="submit" value=" Entreu " alt="Entrar al Aula Virtual">
<IMG BORDER="0" HEIGHT="25" WIDTH="25" SRC="/resources/key.gif" ALT="Entrar en modo seguro" TITLE="Entrar en modo seguro">
</div>
<!--
<Table COLSPAN="2" class="fonsgifs">
<div align="center" class="titol3">
<strong><U>Altres cursos acadèmics</U></SPAN></strong>
</table>
<BR><BR><BR>
<CENTER>
-->
<!--
<img align="center" src="/images/cabeceraOPEN.png" border = 0 align="center" alt="Conferencia OPEN" />
<BR><img align="center" src="/images/ConferenciaSofwareLibre.png" border = 0 align="center" alt="Conferencia Software Libre" />
<BR>7th OpenACS / .LRN Conference
<BR>Conferencia sobre Software Libre en Educación Superior
</CENTER>
-->
</TD>
</TR>
<TR>
<TD class="formulari1" COLSPAN="2" style="text-align:center">
<BR><BR><BR>
</TD>
</TR>
</FORM>
This form uses hidden parameters for security purposes. Every time http://aulavirtual.uv.es/ is displayed these hidden parameters change.
You could try changing your code to do the following:
GET the http://aulavirtual.uv.es/ page.
Parse the resulting HTML to extract the values of the time, token_id, and hash hidden parameters from the form element.
Do the POST as you do now, but pass in these three values instead of the fixed values you are using now.
I'm trying to submit (post) a multidimensional (2D) html-form to a JSP.
In HTML there's the following code:
<tr class="odd">
<td>
<input type="checkbox" name="row1['attribute']" value="Druckerei" id="attribute-1" />
</td>
<td>
<label for="attribute-1">Druckerei</label>
</td>
<td>
<input type="text" name="row1['weight']" size="3" value="0" />
</td>
</tr>
<tr class="even">
<td>
<input type="checkbox" name="row2['attribute']" value="Erscheinungstag" checked="checked" id="attribute-2" />
</td>
<td>
<label for="attribute-2">Erscheinungstag</label>
</td>
<td>
<input type="text" name="row2['weight']" size="3" value="0" />
</td>
</tr>
Is there in JSP a way to handle the 2D post data (perhaps similar to PHP)?
Would it be easier if I had different HTML-Code?
Thank you very much!
No you cannot have 2D array like Rows and Columns. But you can achieve this by sending multiple values for a POST data parameter which works like this:
Your Form might look like this:
<tr class="odd">
<td>
<input type="checkbox" name="attribute" value="Druckerei" id="attribute-1" />
</td>
<td>
<label for="attribute-1">Druckerei</label>
</td>
<td>
<input type="text" name="weight" size="3" value="0" />
</td>
</tr>
<tr class="even">
<td>
<input type="checkbox" name="attribute" value="Erscheinungstag"
checked="checked" id="attribute-2" />
</td>
<td>
<label for="attribute-2">Erscheinungstag</label>
</td>
<td>
<input type="text" name="weight" size="3" value="0" />
</td>
</tr>
And your POST Data will be sent like:
url?attribute=Druckerei,Erscheinungstag&weight=3,3
From the servlets you can access the the POST parameter like:
String[] attributes = request.getParameterValues("attribute");
String[] weights = request.getParameterValues("weight");