This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem with Javascript

 
Swela Jathar
Greenhorn
Posts: 22
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
Vic Hood
Ranch Hand
Posts: 477
Eclipse IDE Java Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use-
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64194
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • 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().
 
Phelipe Maia
Greenhorn
Posts: 16
  • 1
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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
Author and ninkuma
Marshal
Pie
Posts: 64194
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
target.focus();


Eric
 
Swela Jathar
Greenhorn
Posts: 22
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
by using setTimeout and getElementById problem is solved...

Thanks...
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Eric,
target.focus() was not working...
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic