473,386 Members | 1,668 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

A simple text field besides a rectangular box , how to ?

Hi guys,I was thinking about the code to :
write something inside the text box and if the word entered is equal "hero" for example the box next to it will turn green means correct, otherwise it will turn red means wrong,and if nothing entered it stays white.
I really like to know how we code that in javascript using functions, without any CSS or anything else.
That means we have 2 objects a text box and a rectangle for feedback color.
Remark: there is no button at all, the validation will be each time you are typing.


A Bonus question : if someday we decide to change the color with pictures , is it possible to do that?
Thank you very much for your help, much appreciate it.
Jan 9 '10 #1
11 2464
Jibran
30
This is possible. A good example is the password strength custom component which changes color based on the user password length. You can google it.
Jan 9 '10 #2
Dormilich
8,658 Expert Mod 8TB
without any CSS or anything else.
why making it overly complicated like that?
Jan 9 '10 #3
ok you can use whatever you feel conveniable.
Jan 9 '10 #4
Dormilich
8,658 Expert Mod 8TB
the approach is quite straightforward: if the user entered something, i.e. changed the input value (onchange), test if the phrase matches the default. in this case swap the class names of the indication field so that you get the right look (different colour or image).
Jan 9 '10 #5
I appreciate if someone can bring up the solution .Thanks.
Jan 9 '10 #6
Dormilich
8,658 Expert Mod 8TB
you mean, writing the code for you?
Jan 10 '10 #7
acoder
16,027 Expert Mod 8TB
If you want an example, here's one. Not necessarily the best example to learn what's going on because I didn't look for a tutorial and this was one I'd seen years ago. If you search, you'll find many useful tutorials out there.

Try something and, if you get stuck, post back here with your code.
Jan 10 '10 #8
I am not trying to push anyone to write the code, but I am trying to learn.How can an object affect the other object.Those replies about some examples written are not really the best example.Is there something more precise if nobody like to write the code?.
Thank you.
Jan 13 '10 #9
Dormilich
8,658 Expert Mod 8TB
just a little explanation from what I said:

if the user entered something, i.e. changed the input value (onchange),.
here I refer to an event (the event, when a user enters a character in the input field)
Expand|Select|Wrap|Line Numbers
  1. // input refers to the text box element
  2. // onchange is the event, that occurs if a value changes
  3. // doSomething() is the function executed, when the event occurs
  4. // false means it’s in the bubbling phase
  5.  
  6. input.addEventListener("change", doSomething, false);
test if the phrase matches the default.
the condition, when something should be done
Expand|Select|Wrap|Line Numbers
  1. if ("hero" == this.value)
  2. {
  3.     // execute code
  4. }
in this case swap the class names of the indication field so that you get the right look (different colour or image)
styling, such as background colours, background images, etc. should be done using CSS. a very simple way to change the styling is by attaching classes to the elements (see e.g. CSS Zen Garden). if you style the class with CSS, you don’t have to alter the JavaScript, if you need a new styling.
Expand|Select|Wrap|Line Numbers
  1. // a basic approach
  2. // elem refers to the indication element
  3. if ("hero" == this.value)
  4. {
  5.     elem.className = "correct";
  6. }
  7. else
  8. {
  9.     elem.className = "wrong";
  10. }
Jan 13 '10 #10
acoder
16,027 Expert Mod 8TB
What did you not understand about the example I posted? The approach is the same or similar to what Dormilich has been suggesting.
Jan 13 '10 #11
acoder and Dormilich thanks both of you for your reply.
Dormillich , I really appreciate your help and sorry to take your time.
I will try to write the code and see what I got and hopefully learn from it.
Thank you Sir.
Jan 14 '10 #12

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: den.NET | last post by:
i use c++.NET 2003.i simply make a windows form.2 text boxs( takes the number),a buton and another multilined textbox.So simple,when u hit the button it just takes the number in the 1st text box...
2
by: Nikhil Patel | last post by:
Hi all, I am readin an MSDN tutorial on C# arrays. It says, you can have a three-dimensional rectangular array: int buttons = new int; What I don't understand is how can a three dimensional...
5
by: Tiraman | last post by:
Hi, i have some questions about non-rectangular forms 1) i build a form as a non-rectangular by setting the form background to some bmp file and the transparenceyKey to the color which i want...
1
by: xllx.relient.xllx | last post by:
Hi, I have two questions: 1.)Is it true that an rectangular array is really just an single dimensional array that lets itself be treated as a multi-dimensional array? For example the...
2
by: henrywuxg | last post by:
Hi All, I would like to use Period Key(.) besides Tab to toggle from one textbox to another when user is editing IP addresses, which have four textboxes. The function in below works fine with...
1
by: bobmct | last post by:
Again: struggling to convert old-style HTML to html using css. I am trying to create a rectangular box divided into approx three vertical sections. The top section contains an image I would like...
5
by: Yohan Blurp | last post by:
Hi, Here is sample page to show you the problem : <html><body> <form action="/cgi-bin/test.cgi" method="post"> Data Path : <input type="text" size="50" value="C:\Test Data\May 2007.xls"...
4
by: David Tay | last post by:
Is there a text field tag with a value parameter that I can refer to with Javascript besides the input tag? What I have been doing is using Ajax and PHP to pull data out of a database. Then with...
1
by: Brian | last post by:
Hello, I am new to Microsoft access 2007 and I have created a new database. There is a dollar about that I have to change from text to currency format. Also, there is a zip code that I have to...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.