• 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
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

Problem with Javascript

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I am new to Javascript.I have Jsp file which contains form.I have done validation for date in javascript file.when field is blank i wants to set focus to textfiled.
so how can I access textfield in js file?

Thanks in advance.
 
Ranch Hand
Posts: 477
Eclipse IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Use-
 
Sheriff
Posts: 67754
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Vic Hood wrote:Use-


That form of referencing elements is not a good practice. It is antiquated and fragile. It should no longer be used.

Rather, assign an id value to the element and reference the element using document.getElementById().
 
Greenhorn
Posts: 19
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You should use a JS library.. You probably will need more functions in JS and the libraries will help you to do an easier work. Take a look: http://jquery.com/
 
Swela Jathar
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks bear,
but it is not working for me.

see my JSP code:
<td colspan="5">
<html:text property="birthDay" onblur="daySize(this);"
maxlength="2"styleClass="datewidth" tabindex="15"/>
<span class="dashEnglish">
<bean:message key="common.slash"/>
</span>
</td>

I hav called daySize function on onblu.

n js code:

function daySize(target){
var length= target.value.length;
var flag=0;
if(target.value=="" || target.value=='' || target.value.charAt(0)==' ' || length==0){
alert("Please enter day value");

// HERE I WANTS TO SET FOCUS TO TEXTFIELD



else
if(length!=0){
intNumber= parseInt(target.value);
if(!isNaN(intNumber)){
if(target.value>=32 || target.value<=0){
alert("Invalid Day");
flag=1;

}
else if(length==1){
target.value="0"+target.value;
}
}
else{
alert("Day Should Be Integer");
flag=1;
}
}
if(flag==1){
// HERE I WANTS TO SET FOCUS TO TEXTFIELD

}

}



Thanks...

 
Bear Bibeault
Sheriff
Posts: 67754
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please UseCodeTags and please indicate the specific lines of code that you are having problems with. Be sure that your code is formatted properly.

Also, showing server-side markup isn't helpful. Please show the client-side HTNL.
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
target.focus();


Eric
 
Swela Jathar
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
by using setTimeout and getElementById problem is solved...

Thanks...
 
Eric Pascarello
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why do you have to use getElementById when you are already passing in the object to the function?

Eric
 
Swela Jathar
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi Eric,
target.focus() was not working...
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic