[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

ajax call with two radio buttons

Posted on 2009-04-27
8
Medium Priority
?
318 Views
Last Modified: 2013-11-24
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,
0
Comment
Question by:SunScreenCert
  • 4
  • 4
8 Comments
 
LVL 28

Assisted Solution

by:rrz
rrz earned 500 total points
ID: 24247022
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
 
LVL 2

Author Comment

by:SunScreenCert
ID: 24254582
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
 
LVL 28

Assisted Solution

by:rrz
rrz earned 500 total points
ID: 24254983
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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 2

Author Comment

by:SunScreenCert
ID: 24255266
oh great..i would just try this out
0
 
LVL 2

Author Comment

by:SunScreenCert
ID: 24262220

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
 
LVL 28

Expert Comment

by:rrz
ID: 24262391
What is not working ?  
what is printed ?  What source code is sent to the browser ?  
0
 
LVL 2

Author Comment

by:SunScreenCert
ID: 24262889
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
 
LVL 28

Accepted Solution

by:
rrz earned 500 total points
ID: 24264800
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

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hello World !, Thanks : My Sincere thanks to @Michael Male who encouraged me to write an article on this in my  blog (http://scribblejava.wordpress.com). Introduction:       There are several technical issues a developer may face in his…
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
Suggested Courses

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question