PDA

View Full Version : desperate java script text box help


vijk2001
08-12-2002, 04:46 PM
Hi all..
Im new to java script..So some qusetions.
I have a HTML file which is actually a user entry frm with 20-25 fields in it ..some text boxes and some drop downs etc but with one submit button at the end.
Two of my first fields are Link Name and Link Type.(both text edit fields).
These are declared as regular fields inside my HTML code...
My requirement is
If LinkName >=4 chars then Linkcode should automatically be the first 4 chars.
If LinkName < 4 chars then LinkCode should be LinkName PLUS appended O after it.
So i want LinkCode to be automatically ,dynamically populated.

How to do this is .JS and after i have a .JS file WHERE DO I EMBED IT IN HTML.....would it be in top of the HTML page or would it be where fields are declared....
PLS HELP...???
THANKS A LOT IN ADVANCE.........

x_goose_x
08-12-2002, 06:41 PM
Tell me if this works for you:


<script>
function chk_len(what) {
txt = what.LinkName.value;
if (txt.length>4) {
txt = txt.subString(0,3);
}else{
while (txt.length<4) {
txt += "0";
}
}
return true;
}
</script>

<form onSubmit="chk_len(this);">

vijk2001
08-12-2002, 07:22 PM
Thanks a lot but a small question...
How do i embed my JS file ///functions in my HTML code?...
Pls do lemme know..so i can embed the function...
Thanks

x_goose_x
08-12-2002, 07:48 PM
<script src="whatever.js"></script>

,but you don't add the line

<form onSubmit="chk_len(this);">

just add the onSubmit="chk_len(this);" part to your existing form tag.

x_goose_x
08-12-2002, 07:50 PM
<script>
function chk_len(what) {
txt = what.LinkName.value;
if (txt.length>4) {
txt = txt.subString(0,4);
}else{
while (txt.length<4) {
txt += "0";
}
}
what.LinkName.value = txt;
return true;
}
</script>

<form onSubmit="chk_len(this);">

fixed a couple of things

vijk2001
08-12-2002, 08:17 PM
thanks a lot...its kinda cool,,,,,,,,,,,,,,,,,!!!!