File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes HTML, CSS and JavaScript and the fly likes geting focus on radio button Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "geting focus on radio button" Watch "geting focus on radio button" New topic
Author

geting focus on radio button

nabi bux
Ranch Hand

Joined: Mar 14, 2005
Posts: 73
hellow every body i have problem to geting focus on radio button
i have two radio button with the name tile
i have following code but not working
please help
and how to get focus on chechboxes
thanks in advance


code:

myval=dcument.form1;
for (var i=0;i<myval.title.length;i++)
{
if(myval.title[i].checked)
{
mytitle = 1;
}

}

if (mytitle == 0 )
{
alert("You must be select title field");
myval.title[0].focus();
return (false);
}
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10288
    
168

Try this, it worked for me both in Firefox2 and IE6:


[ July 14, 2007: Message edited by: Jaikiran Pai ]

[My Blog] [JavaRanch Journal]
nabi bux
Ranch Hand

Joined: Mar 14, 2005
Posts: 73
thanks for reply but it not working in IE6
it does not check condition if i dont check on any radio button never shsow alert box which is in condition
i want to simple get focus on radion button this my problem
thanks for reply
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10288
    
168

Did you try the exact code that i posted? I have it working in IE6. I get an alert if i dont check and radio button and even the focus is set to the radio button after the alert.
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10288
    
168

Nabi,

There was a small mistake in the earlier code that i had posted (I had used 'i' instead of 'j' at one place in the for loop). I have edited that part and fixed it. Try the code that i have posted and see if it works for you.
nabi bux
Ranch Hand

Joined: Mar 14, 2005
Posts: 73
Thanks too for that
I have got the problem but little confusion
can explaind it
var myval=document.forms[0];

what this line show
wheter the name of my form is form1
and you also use form1 as name of form

var myval=document.form1;
is there any difference of your statement and mine one please explain

i have other problem to got focus on the check boxes

shown below please help



<td align="right"><input type="checkbox" name="edu[]" value="matric"></td>
<td class="mytext">Matric</td>
</tr>
<tr>
<td align="right"><input type="checkbox" name="edu[]" value="inter"></td>
<td class="mytext">Inter</td>
</tr>
<tr>
<td align="right"><input type="checkbox" name="edu[]" value="bsc"></td>
<td class="mytext">Bsc</td>
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10288
    
168

Originally posted by nabi bux:
var myval=document.form1;
is there any difference of your statement and mine one please explain


Nabi, there are multiple ways to access the form in a document. A form is maintained in an array inside the document object. Here are the ways you can access the form:




This way, you first access the forms array and then access the first form in that array. You can change the form index from 0 to some other index depending on how many forms you have and which form you want to access. In the example that we tried out, we just had one form and hence form[0].


This way, you access the forms array and then access the form you are interested in, by its id. In our example, we had given our form the id form1 and hence document.forms.form1

This is a generic way of accessing any element in the document by its id.

All 3 of these methods are going to return you the reference to the form.

Originally posted by nabi bux:
i have other problem to got focus on the check boxes

shown below please help



<td align="right"><input type="checkbox" name="edu[]" value="matric"></td>
<td class="mytext">Matric</td>
</tr>
<tr>
<td align="right"><input type="checkbox" name="edu[]" value="inter"></td>
<td class="mytext">Inter</td>
</tr>
<tr>
<td align="right"><input type="checkbox" name="edu[]" value="bsc"></td>
<td class="mytext">Bsc</td>


Do you mean you are having problem trying out the example on the checkboxes? I see that you have specified the name of the checkbox as edu[]. Change it to edu. Something like:

nabi bux
Ranch Hand

Joined: Mar 14, 2005
Posts: 73
I realy got good knowlege by you thanks for it
but there is problem i thing you post the code about the check box
ok first of all see what i want i have form having array of check box name edu i use post method to get value frm form when i check two check box i use for loop to get the value at second but the problem with your is that when i check all chekbox the last checkbox value transfered on the second page am i right

and secong this is that i want to get focus on the checkbox
let i java script code that check either check boxex are checked or not if no checkbox is cheked then show alert message please check the edu echeckbox and send fox to the check box at the top
I hope you understan what i need
thanks for the reply
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10288
    
168

Originally posted by nabi bux:
but there is problem i thing you post the code about the check box
ok first of all see what i want i have form having array of check box name edu i use post method to get value frm form when i check two check box i use for loop to get the value at second but the problem with your is that when i check all chekbox the last checkbox value transfered on the second page am i right

and secong this is that i want to get focus on the checkbox
let i java script code that check either check boxex are checked or not if no checkbox is cheked then show alert message please check the edu echeckbox and send fox to the check box at the top
I hope you understan what i need
thanks for the reply


I did not completely understand what you meant. But i guess this is what you are looking for, isnt it?


[ July 15, 2007: Message edited by: Jaikiran Pai ]
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10288
    
168

Reading through your post, again, i think i understand what you are asking. You want a array of values (from the checkbox) to be passed to your servlet. When you specify the checkboxes as:



the servlet will be able to get all the checked values by using the getParameterValues method available on the request object. Have a look at getParameterValues(java.lang.String)

As per the javadoc of this method:

Returns an array of String objects containing all of the values the given request parameter has, or null if the parameter does not exist.

If the parameter has a single value, the array has a length of 1.


So, all you have to do in your servlet is



This way you will get all the checked values.
nabi bux
Ranch Hand

Joined: Mar 14, 2005
Posts: 73
Thanks but i m using sever side PHP
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Originally posted by nabi bux:
Thanks but i m using sever side PHP


You can let the PHP interpreter know that you are sending multiple values by appending '[]' to the end of the element's name attribute.

Example:

[ July 16, 2007: Message edited by: Ben Souther ]

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: geting focus on radio button