• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

form parameters

 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a form which i am validating in javascript, i want that when the user fills in his ecnumber the form should get submitted and query a database and the other details like his name and age and position should be displayed in the same form where these fields appear, now i am able to send the form when the focus is lost,the place i am really stuck up is that I want that the results of the query should be displayed in the same form in respective text fields,please help me out in this...
 
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This can be done like this :
first declare some string variables
say
String name= "" //ie initialise it to ""
also declare a
hidden variable as refreshFlag = "N"
You will submit your page through a javascript function..
just before submitting make the refreshFlag ="Y"
In the same jsp or servlet do request.getparameter of refreshFlag ... if it is "N" then the jsp/servlet is loaded fpr the first time so no querry will be called... now say you put the ecnumber and then submit the form refreshFlag is "Y"
so make the querry
eg.
select name from ...... where ecnumber = ......
.......
......
name = rs.getString(1);
so the variable name has got the name from database after the page is refreshed
<input type = text value = <%=name%> >
initially name = "" so the text field will be blank but after it is refreshed it has got the actual name from database.
All the best )
 
amit malhotra
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanx a lot for the reply, i will definately try out the same
and get back to you in case I have any doubts
Rgds
Amit
 
amit malhotra
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by mou haj:
Hello mou
this is the code that i originally have with some modifications done..but it's still not working
<html>
<head>
<title>Feedback Form</title>
<script>
function isBlank(s){
var len=s.length
var i
for(i=0;i<len;i++){
if(s.charAt(i)!=" ")
return false
}
return true
}

function validate(fieldName,fieldValue){
if(isBlank(fieldValue)){
alert(fieldName+" cannot be blank !")
document.feedbackform.ecnumber.focus()
return false
}
return true
}

function fieldValidate(fieldName,fieldValue){
var checkOk="1234567890";
var checkStr=fieldValue;
if(checkStr.length>0)
{
var allValid = true;
for (i = 0;i<checkStr.length;i++)
{
ch = checkStr.charAt(i);
for (j = 0;j < checkOk.length;j++)
if (ch == checkOk.charAt(j))
break;
if (j == checkOk.length)
{
allValid = false;
break;
}
}
if (!allValid)
{
alert(fieldName+" is not valid!");
document.feedbackform.ecnumber.focus()
return false;
}
}
}


function strValidate(fieldName,fieldValue)
{
if(fieldValue.length<9){
alert(fieldName+"must contain 9 characters !")
document.feedbackform.ecnumber.focus()
return false;
}
return true
}


function validateECNumber(){

if(validate("The ECNumber field",document.feedbackform.ecnumber.value) | | fieldValidate("The ECNumber field",document.feedbackform.ecnumber.value) | | strValidate("The ECNumber field",document.feedbackform.ecnumber.value)){

document.forms[0].action="userfeedback_form.jsp";
document.forms[0].submit()
boolean validate=true


}

}
</script>
</head>
<body background="BACKGROUND1.jpg" style="font-family: Verdana; font-size: 10pt" onLoad="document.feedbackform.ecnumber.focus()">
<br><p>
<table border="0" width="780" cellspacing="0" cellpadding="0">
<tr>
<td width="100%">
<table border="0" width="100%" height="241">
<tr>
<td width="100%" background="HEADER1.jpg" height="77"> </td>
</tr>
<tr>
<td width="100%" height="152">
<p align="center"><b><font color="#000080">Feedback Form</font></b></p>
<table border="0" width="100%">
<tr>
<form name="feedbackform" onSubmit="return validateECNumber()" method="post">
<td width="32%"><font color="#000080"><b><font size="2">Please Enter your EC Number</font>
</b>

</font>
</td>
<td width="68%"><font color="#000080">

<input type="text" name="ecnumber" size="9" maxlength="9" onBlur="validateECNumber()">
</form>
<%
boolean validate=false;
%>
<%@ page import="java.sql.*" %>
<%
if(validate){
String empecnumber=request.getParameter("ecnmuber");
String driver="sun.jdbc.odbc.JdbcOdbcDriver";
String protocol = "jdbc dbc:employeedatabase";
String query = "SELECT * FROM employeedatatable where ecnumber like 'empecnumber' " ;
Connection connection;
Statement statement;
ResultSet rs;
Class.forName(driver);
connection = DriverManager.getConnection(protocol);
statement = connection.createStatement();
rs = statement.executeQuery(query);
while(rs.next()){
String name = rs.getString(1);
String phone = rs.getString(2);
String location = rs.getString(3);
out.println(phone);
}
}
%> </td>

</tr>
<tr>
<td width="46%"><font size="2" color="#000080"><b>Name:  
<input type="text" name="ename" size="30" maxlength="9" value="name"></b></font></td>
<td width="54%"><font size="2" color="#000080"><b>Location :  
<input type="text" name="elocation" size="6" maxlength="9"></b></font></td>
</tr>
<tr>
<td width="46%"><font size="2" color="#000080"><b>Phone: 
<input type="text" name="ephone" size="6" maxlength="9"></b></font></td>
<td width="54%"> </td>
</tr>
<tr>
<td width="100%" colspan="2">
<p align="center"><font size="2" color="#000080"><b>We would like to
head from you, Please Enter your suggestions here</b></font></p>
</td>
</tr>
<tr>
<td width="100%" colspan="2">
<p align="center"><b><font color="#000080"><font size="2">Comments
and Suggestions:</font> </font></b><br>
<br>
   <textarea rows="8" name="ecomments" cols="50"></textarea>
<p align="center"> </p>
<p align="center"><input type="submit" value="Submit">     <input type="reset" value="Reset" name="reset"></p>

<p align="center"> </p>

<p> </p>
</td>
</tr>
</table>

</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>
please suggest the changes that are necessary

 
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Amit,
Here is sample code specially written for u, hope this will help u, if u still have some prob feel free to contact me..
<html>
<script >
function callMe(){
tempForm.secret.value = 'Y' ;
tempForm.submit();
}
</script>
<%
String firstTextString = "" ;
String secondTextString = "" ;
String thirdTextString = "" ;
String dynamicValueString = "" ;
String secretString = request.getParameter("secret") ;
if(secretString != null && secretString.toUpperCase().equals("Y")){
firstTextString = request.getParameter("first") ; ;
secondTextString = request.getParameter("second") ; ;
thirdTextString = request.getParameter("third") ; ;
dynamicValueString = "I m from database" ;
%>
<body onLoad="javascript:tempForm.fourth.focus();">
<%
}else{
%>
<body onLoad="javascript:tempForm.first.focus();">
<%
}
%>

<form name="tempForm" action="testing.jsp">
<input type=hidden name=secret value=N>
<input type=text name=first value="<%=firstTextString%>">
<input type=text name=second value="<%=secondTextString%>">
<input type=text name=third value="<%=thirdTextString%>" onBlur="javascript:callMe();">
<input type=text name=fourth value="<%=dynamicValueString%>">
</form>
</body>
</html>
 
amit malhotra
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanx a lot for the reply i will try out the changes now itself and mail you back

Rgds
Amit
 
amit malhotra
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Yogen Vadnere:
Hello Yogen,
thanx a lot for your script , it did work and i am using it in one of my projects....and finally relieved me of the stress i was undergiong for 3 days.
thanx,

 
Whatever. Here's a tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic