Multiple Javascript funtions not working in JSp

R

ruds

Hi,
I have a web-app in which a from is to be filled and requires dynamic
updating of the form fields from the database.
For this I have used one Javascript function to refresh the page with
new data. but then my other funtions like checking mail-id and check
if all fields are filled do not activate when called onBlur() or on
Submit().
What might be causing the problem?
My code:

<HEAD>
<TITLE>Main Page</TITLE>
<SCRIPT language=javascript>
var Aggregate,Domain;
function Select_Index1(form)
{
Domain = document.f1.domain.options
[document.f1.domain.selectedIndex].value
Aggregate = document.f1.Aggregate.options
[document.f1.Aggregate.selectedIndex].value
var HREF="./AddNewReq.jsp?D="+Domain+"&Agg1="+Aggregate
window.open(HREF, "_self")
}

function isInt(s)
{
var i;
var reg= new RegExp ("[^0-9]");
i = reg.test (s.value);
if(i)
{
alert("Please enter Numeric Value for Contact Number");
s.value = "";
s.focus();
} }

function checkId()
{
var x=document.f1;
var at=x.rmailid.value.indexOf("@");
var dot=x.rmailid.value.lastindexOf(".");
Flag="True";
if((at==-1)||(dot==-1))
{
x.rmailid.value=" ";
alert("Not valid Email Id");
x.rmailid.focus();
Flag="False";
} }
</script>
</head>
<body>
<FORM ACTION="./SubmitReq.jsp" name="f1" METHOD="POST"
onsubmit="submitme(f1)">
<TABLE NOBORDER cellpadding=5>
<TR>
<TD><B><FONT FACE="ARIAL" >Analysis Domain </FONT></B></TD>
<TD><select name="domain" onchange="Select_Index1(this.FORM)">
<OPTION VALUE="" selected>[Select Domain]</OPTION>
<%if(d1.equals("")) {%>
<OPTION VALUE="dur" >Durability</OPTION>
<OPTION VALUE="mbd">MBD</OPTION>
<%}
else {
if(d1.equals("dur")) {%>
<OPTION VALUE="dur" selected>Durability</OPTION>
<OPTION VALUE="mbd">MBD</OPTION>
<%}
else{%>
<OPTION VALUE="dur" >Durability</OPTION>
<OPTION VALUE="mbd" selected>MBD</OPTION>
<%}
}%>
</select>
</TD>
</TR>
<TR>
<TD><B><FONT FACE="ARIAL" >Aggregate</FONT></B></TD>
<TD><select name="Aggregate" size="1" onchange="Select_Index1
(this.FORM)">
<OPTION VALUE="" selected>[Select Aggregate]</OPTION>
<%
rs=stmt.executeQuery("select * from Aggregate where
Domain='"+d1+"'");
while(rs.next())
{ //out.println("d1="+d1);
String agg=rs.getString(2);
//System.out.println("agg="+agg);
if(Aggregate.equals(agg))
{
%>
<OPTION VALUE="<%=agg%>" selected><%=agg%></OPTION>
<%
}
else
{ %>
<OPTION VALUE="<%=agg%>"><%=agg%></OPTION>
<% }
}
stmt.close();
%>
</select>
</TD>
</TR>
 
T

Thomas 'PointedEars' Lahn

ruds said:
I have a web-app in which a from is to be filled and requires dynamic
updating of the form fields from the database.
For this I have used one Javascript function to refresh the page with
new data. but then my other funtions like checking mail-id and check
if all fields are filled do not activate when called onBlur() or on
Submit().
What might be causing the problem?

There is no "might" here. It is quite obvious that you don't know what you
are doing.

*Your* code?
<HEAD>
<TITLE>Main Page</TITLE>
<SCRIPT language=javascript>

[lots of outdated/deprecated/pointless/invalid/server-side code]

<http://jibbering.com/faq/#posting> pp.


PointedEars
 
R

ruds

Hi,
I have a web-app in which a from is to be filled and requires dynamic
updating of the form fields from the database.
For this I have used one Javascript function to refresh the page with
new data. but then my other funtions like checking mail-id and check
if all fields are filled do not activate when called onBlur() or on
Submit().
What might be causing the problem?
My code:

<HEAD>
<TITLE>Main Page</TITLE>
<SCRIPT language=javascript>
var Aggregate,Domain;
function Select_Index1(form)
{
Domain = document.f1.domain.options
[document.f1.domain.selectedIndex].value
Aggregate = document.f1.Aggregate.options
[document.f1.Aggregate.selectedIndex].value
var HREF="./AddNewReq.jsp?D="+Domain+"&Agg1="+Aggregate
window.open(HREF, "_self")

}

function isInt(s)
{
var i;
var reg= new RegExp ("[^0-9]");
i = reg.test (s.value);
if(i)
{
alert("Please enter Numeric Value for Contact Number");
s.value = "";
 s.focus();

} }

function checkId()
{
var x=document.f1;
var at=x.rmailid.value.indexOf("@");
var dot=x.rmailid.value.lastindexOf(".");
Flag="True";
if((at==-1)||(dot==-1))
{
x.rmailid.value=" ";
alert("Not valid Email Id");
x.rmailid.focus();
Flag="False";}  }

</script>
</head>
<body>
<FORM ACTION="./SubmitReq.jsp"  name="f1"   METHOD="POST"
onsubmit="submitme(f1)">
<TABLE NOBORDER cellpadding=5>
<TR>
<TD><B><FONT  FACE="ARIAL" >Analysis Domain </FONT></B></TD>
<TD><select  name="domain" onchange="Select_Index1(this.FORM)">
<OPTION VALUE="" selected>[Select Domain]</OPTION>
<%if(d1.equals("")) {%>
 <OPTION VALUE="dur" >Dura</OPTION>
 <OPTION VALUE="mbd">MBD</OPTION>
 <%}
 else {
 if(d1.equals("dur")) {%>
 <OPTION VALUE="dur" selected>Dura</OPTION>
 <OPTION VALUE="mbd">MBD</OPTION>
 <%}   else{%>
 <OPTION VALUE="dur" >Dura</OPTION>
 <OPTION VALUE="mbd" selected>MBD</OPTION>
 <%}  }%>
 </select>
 </TD>
 </TR>
 <TR>
 <TD><B><FONT FACE="ARIAL" >Aggregate</FONT></B></TD>
 <TD><select  name="Aggregate" size="1" onchange="Select_Index1(this.FORM)">
  <OPTION VALUE="" selected>[Select Aggregate]</OPTION>
 <% rs=stmt.executeQuery("select * from Aggregate where Domain='"+d1+"'");     while(rs.next())
 {
     String agg=rs.getString(2);
    if(Aggregate.equals(agg))
    { %>
    <OPTION VALUE="<%=agg%>" selected><%=agg%></OPTION>
    <% }
     else {    %>
   <OPTION VALUE="<%=agg%>"><%=agg%></OPTION>
   <%   }
   } stmt.close(); %>
   </select>
   </TD>
   </TR>
<TR><TD><B><FONT FACE="ARIAL" >Contact No: </B></TD>
<TD><input type=text name="rno" size=10 onBlur="isInt(rno);" </
TD>
</TR>
<TR>
<TD><B><FONT FACE="ARIAL" >Email id: </B></TD>
<TD><input type=text name="rmailid" size=50 onSubmit="return checkId
()">&nbsp;&nbsp;&nbsp</TD>
</TR>
</body>
</html>

As seen in the code I want to refresh the page when the user selects
Domain and also when the user selects an aggregate.This works
correctly, but the other functions to check for mail id and integer do
not work.
 
G

Garrett Smith

ruds said:
Hi,
I have a web-app in which a from is to be filled and requires dynamic
updating of the form fields from the database.

Prefilling them from the server would seem to be the best option:
For this I have used one Javascript function to refresh the page with
new data. but then my other funtions like checking mail-id and check
if all fields are filled do not activate when called onBlur() or on
Submit().

It is hard to determine what you are asking.
What might be causing the problem?
My code:
[snip]

I know this will sound harsh, but throw that out. It isn't any good. Get
a fresh start on it.

You can have the page submit to itself and then check the data. It would
be a good idea to decouple the server side and client side code.

See also: http://jibbering.com/faq/faq_notes/clj_posts.html#ps1DontWork

Garrett
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,767
Messages
2,569,570
Members
45,045
Latest member
DRCM

Latest Threads

Top