Sathish David Kumar N
asked on
How to get the Jsp value in javascript
Hi ,
I have a dropdown which have value like this site(site 123) . how can i get the value of this selected drop down
if i use document.getElementById() means it give site(site after that it will drauncate
how can get full value .
how can get the full value . It will trancate after the sepace !
I have a dropdown which have value like this site(site 123) . how can i get the value of this selected drop down
if i use document.getElementById() means it give site(site after that it will drauncate
how can get full value .
how can get the full value . It will trancate after the sepace !
can you share the jsp code that you are trying with? As @cesardanielleon is saying it should not truncate after space.
did you tried something like this for the name or value
<select id="sel" name="sel">
<option value="site(site <%= //jsp code %>)">site(site 123)</option>
</select>
did you tried something like this for the name or value
<select id="sel" name="sel">
<option value="site(site <%= //jsp code %>)">site(site 123)</option>
</select>
ASKER
<select id="sel" name="sel">
<option value="site(site 123)>site(site 123)</option>
<option value="site(site456)>site( site456)</ option>
</select>
i want to get the selected value in javascript ?
if i select site(site456) and in java script function using document.getElementById()
i get the correct result site(site456)
but i choose site(site 123) means i am getting the site(site upto this only .
<option value="site(site 123)>site(site 123)</option>
<option value="site(site456)>site(
</select>
i want to get the selected value in javascript ?
if i select site(site456) and in java script function using document.getElementById()
i get the correct result site(site456)
but i choose site(site 123) means i am getting the site(site upto this only .
check this;you missed quotes in the option value.
<script>
function ex()
{
alert(document.frm.sel.opt ions[docum ent.frm.se l.options. selectedIn dex].value )
}
</script>
<form name="frm">
<select id="sel" name="sel" onChange="ex()">
<option value="site(site 123)">site(site 123)</option>
<option value="site(site456)">site (site456)< /option>
</select>
</form>
<script>
function ex()
{
alert(document.frm.sel.opt
}
</script>
<form name="frm">
<select id="sel" name="sel" onChange="ex()">
<option value="site(site 123)">site(site 123)</option>
<option value="site(site456)">site
</select>
</form>
if you want to fetch through id you can do like this;
alert(document.getElementB yId("sel") .options[d ocument.ge tElementBy Id("sel"). options.se lectedInde x].value)
alert(document.getElementB
@dravidnsr: you haven't shared the jsp code that you have written. Please share the same so that we can help you.
Also, please check if the quotes are given properly as a fellow expert has also mentioned.
Also, please check if the quotes are given properly as a fellow expert has also mentioned.
ASKER
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%
<%@ taglib uri="/WEB-INF/displaytag-1
<%@ taglib uri="/WEB-INF/struts-html.
<%@ taglib uri="/WEB-INF/struts-bean.
<%@ taglib uri="/WEB-INF/struts-logic
<%@ taglib uri="http://java.sun.com/jstl/core-rt" prefix="c-rt"%>
<%@ page import="com.merck.mrl.iftr
<%@ page import="java.util.ArrayLis
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>MRL-IFTRS</title>
</head>
<link rel="stylesheet" type="text/css" href="css/screens_new.css"
<link rel="stylesheet" type="text/css" href="css/style.css">
<script type="text/javascript">
var xmlhttp;
var context='<%= request.getContextPath() %>';
var a=/^ *[0-9]+ *$/ ;
function initRequest()
{
if (window.XMLHttpRequest)
{
xmlhttp = new XMLHttpRequest();
}
else if (window.ActiveXObject)
{
isIE = true;
xmlhttp = new ActiveXObject("Microsoft.X
}
}
function getSite()
{
initRequest();
var studyNo=document.getElemen
var url = context+"/AjaxUtilAction.d
url = url + "?callType=listOfSitesMapp
url = url + "&studyNo="+ studyNo;
xmlhttp.open("GET", url, true);
xmlhttp.onreadystatechange
xmlhttp.send();
}
function getShipNo()
{
initRequest();
var siteId = document.getElementById("s
var siteId1 = siteId.options[siteId.sele
alert(siteId1);
var studyNo=document.getElemen
return false;
var url = context+"/AjaxUtilAction.d
url = url + "?callType=listOfShipNoToS
url = url + "&studyNo="+ studyNo;
url = url + "&siteId="+ siteId;
xmlhttp.open("GET", url, true);
xmlhttp.onreadystatechange
xmlhttp.send();
}
function fetchSite()
{
if(xmlhttp.readyState == 4)
{
var rText = xmlhttp.responseText;
var records=rText.split(",");
var fieldvalue;
var i=0,j=0;
var placecontrol="<select name=siteId id=siteId onchange=getShipNo() > <option value=Select>Select</optio
for(i=0;i<records.length-1
{
fieldvalue=records[i].spli
placecontrol+="<option value="+fieldvalue[0]+">"+
}
placecontrol+="</select>";
document.getElementById("S
document.getElementById("S
}
}
function fetchShipNo()
{
if(xmlhttp.readyState == 4)
{
var rText = xmlhttp.responseText;
var records=rText.split(",");
var fieldvalue;
var i=0,j=0;
var placecontrol="<select name=shipNo id=shipNo > <option value=Select>Select</optio
for(i=0;i<records.length-1
{
fieldvalue=records[i].spli
placecontrol+="<option value="+fieldvalue[0]+">"+
}
placecontrol+="</select>";
document.getElementById("S
document.getElementById("S
}
}
function numValidation(tableID,i){
var table = document.getElementById(ta
var myElements = table.getElementsByTagName
var trlen = table.rows.length;
var check=parseInt(i)+1;
var x=document.getElementById(
var recQTY=parseInt(document.g
if(!a.test(recQTY)){alert(
else{
var shippedQTY=(parseInt(x[3].
var totQTY=shippedQTY-recQTY;
if(totQTY<0)
{
alert("Please Enter Recevied QTY is less than Shipped QTY");
}
else{document.getElementBy
}
return false;
}
function demagedQTYValidation(table
{
if(!a.test(parseInt(docume
}
function saveMethod(tableID)
{
var table = document.getElementById(ta
var myElements = table.getElementsByTagName
var trlen = table.rows.length;
var j=0;
var str = new String();
try{
for(i=1; i<trlen; i++)
{
var x=document.getElementById(
var check=parseInt(i)-1;
var type = ackAncilForm.elements[i-1]
if (document.getElementById('
if(trlen== 2)
{
if((document.getElementByI
str = str + x[1].innerHTML+','
+ x[2].innerHTML+','
+ x[3].innerHTML+','
+ x[4].innerHTML+','
+ x[5].innerHTML+','
+ document.getElementById('r
+ document.getElementById('n
+ document.getElementById('d
}
else
{
j=j+1;
if((document.getElementByI
str = str + x[1].innerHTML+','
+ x[2].innerHTML+','
+ x[3].innerHTML+','
+ x[4].innerHTML+','
+ x[5].innerHTML+','
+ document.getElementById('r
+ document.getElementById('n
+ document.getElementById('d
}
}
}
if (j==0){throw 'selectAcn';}
}catch(er){
if(er=="recQTY"){alert("Pl
if(er=="selectAcn"){alert(
}
document.ackAncilForm.sele
document.ackAncilForm.acti
document.ackAncilForm.subm
}
</script>
<body>
<jsp:include page="/jsp/common/header_n
<div align="left">
<jsp:include page="/jsp/common/Menu_new
</div>
<font color="red"><html:errors /></font>
<div align="center">
<fieldset style="width: 90%"> <legend class="legendHeader" style="background-color: "><b>Acknowledge the Ancillary Received at Site</b></legend>
<html:form action="/ackAncilShip">
<table align="center">
<tr>
<td align="left"><bean:message
<td align="left">
<%
ArrayList studyNo = (ArrayList)request.getAttr
if (studyNo != null && studyNo.size() > 0){
out.println("<CENTER>");
%><select name="studyNo" onchange="getSite()" id="studyNo">
<option value='0'>Select</option>
<%
for (int i=0;i<studyNo.size();i++) {
out.println("<option value='"+studyNo.get(i) + "'");
if(request.getSession().ge
{
if(((String)request.getSes
{
out.println("selected='sel
}
}
out.println(">"+ studyNo.get(i) + "</option>");
}%>
</select><%
out.println("</CENTER>");
}
%>
</td>
</tr>
<tr>
<td align="left"><bean:message
<td align="left">
<div id="SourceSiteList" ></div>
<div id="SourceSiteListDefault"
<select name="siteId1" id="siteId1" >
<option value="select">Select</opt
</select>
</div>
</td>
</tr>
<tr>
<td align="left"><bean:message
<td align="left">
<div id="ShipNoList" ></div>
<div id="ShipNoListDefault" align="center" >
<select name="shipNoList1" id="shipNoList1" >
<option value="select">Select</opt
</select>
</div>
</td>
</tr>
<tr> <td><html:submit value="Submit"/></td>
</tr>
</table>
</html:form>
</fieldset>
<%
String studyNo = session.getAttribute("list
String siteId = session.getAttribute("site
String shipNo = session.getAttribute("ship
%>
<%if(!studyNo.equals("")){
<fieldset style="width: 90%">
<table>
<tr><td><font color="blue" size="2">Study : </font><font size="2"><%=studyNo%></fon
<td><font color="blue" size="2">Site : </font><font size="2"><%=siteId%></font
<td><font color="blue" size="2">Shipped No : </font><font size="2"><%=shipNo%></font
</table>
</fieldset>
<%} %>
<c-rt:if test="<%= request.getAttribute("fetc
((ArrayList)request.getAtt
<fieldset style="width: 90%">
<legend align="left" style="vertical-align: middle"><b>
<bean:message key="label.ancillaryList"/
</legend>
<form name="ackAncilForm" method="post">
<% int i =0; %>
<display:table name="fetchShipedAncilList
cellpadding="5" class="data" requestURI="/ackAncilShip"
<display:column>
<INPUT TYPE="checkbox" name="cbox<%=i%>" id="cbox<%=i%>" ></INPUT>
</display:column>
<display:column property="achilName" title="Ancillary Name" align="center"/>
<display:column property="batchNo" title="Batch No" align="center" />
<display:column property="shipedQTY" title="Shipped Quantity" align="center" />
<display:column property="expDate" title="Expiry Date" align="center" />
<display:column property="invoiceNo" title="invoiceNo" align="center" class="hidden" headerClass="hidden" media="html" />
<display:column title="Recevied Quantity" >
<input type="text" name="receviedQTY" Id="receviedQTY<%=i%>" value="0" onblur="numValidation('pro
</display:column>
<display:column title="Demaged Quantity" >
<input type="text" name="demageQTY" Id="demageQTY<%=i%>" value="0" >
</display:column>
<display:column title="Not Recevied Quantity" >
<input type="text" name="notRecQTY" Id="notRecQTY<%=i%>" value="0" readonly="readonly">
</display:column>
<%=i++ %>
</display:table>
<table width="100%">
<tr>
<td align="left" width="10%">
</td>
<td align="left" width="10%">
<input type="hidden" name="selectedAncil" Id="selectedAncil" >
</td>
<td align="center" colspan="9"><br/><br/> <input type="button" name="Get Ancillaries "
value="Get Ancillaries" onclick="saveMethod('proce
</td>
<td align="left" width="10%">
</td>
<td align="left" width="15%">
</td>
</tr>
</table>
<input type="hidden" name="studyNo" value="<%=studyNo%>">
<input type="hidden" name="siteId" value="<%=siteId%>">
<input type="hidden" name="shipNo" value="<%=shipNo%>">
</form>
</fieldset>
</c-rt:if>
<center>
<c-rt:if test="<%= request.getAttribute("depo
((ArrayList)request.getAtt
<font color="red"> <c-rt:out value="No Records Exists for this invoice."></c-rt:out></fon
</c-rt:if>
</center>
</div>
<%@ include file="/jsp/common/footer.j
</body>
</html>
alert.JPG
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Gr8 answer Man ,
i am looking this for last 2 weeks . When wrongly check so that only i didnt give points early.
Thanks alot man
i am looking this for last 2 weeks . When wrongly check so that only i didnt give points early.
Thanks alot man
<select id="sel" name="sel">
<option value="site(site 123)">site(site 123)</option>
</select>