ajax call with two radio buttons

Hi,

I have a field billable and i have two radio buttons yes and no. If app.getBillable value is 0, then i want the radio button yes be checked else i want no be checked. Please tell me how can i achieve this conditional checking in a servlet file.

Thanks,
LVL 2
SunScreenCertAsked:
Who is Participating?
 
rrzConnect With a Mentor Commented:
Did you try browsing to the servlet with a regular request(not AJAX0 to see what your servlet outputs ?  If your servlet doesn't output what you want then post the whole servelt code here.
0
 
rrzConnect With a Mentor Commented:
What do you  need AJAX for ?  
Does the demo code below here, help you ?
<%
  String yesChecked = "";
  String noChecked = "";
  String checkString = "checked = \"checked\"";
  String billable = request.getParameter("billable");
  if(billable == null)billable = "";
  if("0".equals(billable))yesChecked = checkString;
   else noChecked = checkString;
%>
<html>
<head>
</head>
<body>
<form name="myForm">
<input type="text" name="billable" value="<%=billable%>"/>
<input type="radio" name="x" value="yes" <%=yesChecked%>/>
<input type="radio" name="x" value="no" <%=noChecked%>/>
<input type="submit"/>
</form>
</body>
</html>

Open in new window

0
 
SunScreenCertAuthor Commented:
No,
Please refer to the code below. This is a .java file. Since i have used ajax, i am using this file for the creation of table and columns.

out.println("<tr><td>Billing Model");
                             
            out.print("<tr><td><input type='radio' name='appStatusDescription'value='0'>Prepaid<br>");
            out.print("' </td>");
             out.print("<td><input type='radio' name='appStatusDescription'value='1' checked>Postpaid<br>");
             
                  out.print("' </td></tr>");

Now all this is in a servlet whose response is taken by xmlhttprequest and the div of the jsp is updated.  Now based on the app.getBillingModel i want that either of them should be checked. So i want all this done in this servlet file. Please tell me how do i go for it.
0
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

 
rrzConnect With a Mentor Commented:
I believe my sample code that I posted above here demonstrates that.
But below I will try to demonstrate in your servlet.
String yesChecked = "";
String noChecked = "";
String checkString = "checked = \"checked\"";
String billable = app.getBillingModel();
if(billable == null)billable = "";
if("0".equals(billable))yesChecked = checkString;
   else noChecked = checkString;
out.println("<tr><td>Billing Model");                
out.print("<tr><td><input type='radio' name='appStatusDescription' value='0' " + yesChecked + ">Prepaid<br>");
out.print("' </td>");
out.print("<td><input type='radio' name='appStatusDescription' value='1' " + noChecked + ">Postpaid<br>");
out.print("' </td></tr>");

Open in new window

0
 
SunScreenCertAuthor Commented:
oh great..i would just try this out
0
 
SunScreenCertAuthor Commented:

I did the same thing but it is not working


String yesChecked = "";
            String noChecked = "";
            String checkString = "checked = \"checked\"";
            int billingModel = app.getBillingModel();
            if(billingModel == 0)
                yesChecked = checkString;
            else
                noChecked = checkString;
            out.println("<tr><td>Billing Model");
            out.print("<tr><td><input type='radio' name='appStatusDescription' value='0' " + yesChecked + ">Prepaid<br>");
            out.print("</td>");
            out.print("<td><input type='radio' name='appStatusDescription' value='1' " + noChecked + ">Postpaid<br>");
            out.print("</td></tr>");

0
 
rrzCommented:
What is not working ?  
what is printed ?  What source code is sent to the browser ?  
0
 
SunScreenCertAuthor Commented:
I see that none of the fields are checked when i use this code.
I don't see these fields in the source code  because all of the whole table with the billing model row is  coming from servlets and i have a div which it is updating, so i see only the div there like this
<div id="appresults" name="appresults">
          </div>
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.