Link to home
Start Free TrialLog in
Avatar of Atul Rokade
Atul RokadeFlag for India

asked on

fetch url variable in textbox dynamically

Here is my html code where i creating dynamic textbox for insert using jsp
function getinput()
{
index ++;
var singleRecord = "";
singleRecord += " Employee_id : <input type='text' READONLY name='txt_Employee_id"+index+"'value='<%=request.getParameter("employee_id")%>'>";
singleRecord += " Project_name : <input type='text' name='txt_project_name"+index+"'>";
singleRecord += "Project/Task : <input type='text' name='txt_Header"+index+"'>";
singleRecord += "Department : <input type='text' name='txt_Department"+index+"'>";
singleRecord += "Description : <input type='text' name='txt_description"+index+"'>";
<!--singleRecord+="Date : <input type='date'  name='datainsertdate"+index+"'>"; --->
singleRecord += "<hr/>";
$("#inputs").append(singleRecord);
$("#count").val(index);
}

</script>

</head>

<body background="123-slideshow\blue_background.jpg">
<form action="EmployeeVendorValidation.jsp" method="post">

   
     <br><br><br><br>    
<input type="hidden" name="count" id="count"/>



<div id="inputs">
</div>
<button type="button" onclick="getinput()" class="button button5">Add</button>

&nbsp;
<button type="submit" class="button button2">Submit</button>

jsp:

 Class.forName("oracle.jdbc.driver.OracleDriver");
          Connection con=DriverManager.getConnection("jdbc:oracle:thin:@172.18.114.213:1821:godb","xe","ex");
       PreparedStatement ps = con.prepareStatement("insert into employee_task values(?,?,?,?,?,?)");
       
int count = Integer.parseInt(request.getParameter("count"));

 



if(count >0){
   
for(int i=1;i<=count;i++){
   

 //employee_id_numeric=Integer.parseInt(request.getParameter("employee_id")+i);
 String employee_id = request.getParameter("txt_Employee_id"+i);
String txt_project_name = request.getParameter("txt_project_name"+i);
String get_header = request.getParameter("txt_Header"+i);
String get_department = request.getParameter("txt_Department"+i);
String get_description = request.getParameter("txt_description"+i);

ps.setString(1, employee_id);  
ps.setString(2, txt_project_name);
ps.setString(3, get_header);
ps.setString(4, get_department);
ps.setString(5, get_description);
  ps.setDate(6,new java.sql.Date(System.currentTimeMillis()));

ps.addBatch();
}
}
ps.executeBatch();
out.println("<script type=\"text/javascript\">");
   out.println("alert('Data Submited');");
   out.println("</script>");

i want to fetch employee_id dynamically in textbox    http://localhost:8080/EmployeeRegistration/EmployeeVendorTask.html?*employee_id=12344* but i unable to fetch value

i check in jsp its showing me null value always i'm passing variable in this format to other page : response.sendRedirect("EmployeeVendorTask.html?employee_id="+Employee_id);

i edit in javascript like this var name='<%= session.getAttribute( "Employee_id" ) %>';
and in function i concatenate singleRecord += " Employee_id : <input type='text' READONLY name='txt_Employee_id"+index+"value="+name+">"; but still i enable to fetch value added image also for clear understand


i tested in jsp page by this code and i get employee_id but in textbox i unable to fetch
String test= session.getAttribute("Employee_id").toString();
      out.println("<script type=\"text/javascript\">");
 out.write("alert('You are successfully Login at:" + test + "')");
 out.println("</script>");
employee_id.JPG
Avatar of Atul Rokade
Atul Rokade
Flag of India image

ASKER

i got solution on this
If you found your own solution, would you mind posting it here? That way it can help anyone else who runs into this problem.
This question needs an answer!
Become an EE member today
7 DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.