• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

geting focus on radio button

 
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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);
}
 
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try this, it worked for me both in Firefox2 and IE6:


[ July 14, 2007: Message edited by: Jaikiran Pai ]
 
nabi bux
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks but i m using sever side PHP
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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 ]
reply
    Bookmark Topic Watch Topic
  • New Topic