...

View Full Version : setting up default datatype values for certain values in an input box



whammond
07-10-2002, 05:08 PM
Ok, Lets say I have 4 input boxes.
The word either: "test", "prod", or "go" will be typed into the first input box.



Input box1: "Go"

Input box2: ______________

Input box3: ______________

Input box4: ______________


Upon completion of this, in the final three text boxes, I want

"a"
"b"
and "c"

to be populated in the other three text boxes. For each word: "test, "proud", and "go" will be a set default that should appear in the following three boxes. With this type of algorithm...how would I script this??

RadarBob
07-10-2002, 06:03 PM
switch (document.theform.box1.value) {
case "go":
document.theform.box2.value = "a";
document.theform.box3.value = "b";
document.theform.box4.value = "c";
break;

case "test":
document.theform.box2.value = "Larry";
document.theform.box3.value = "Moe";
document.theform.box4.value = "Curley";
break;

case "proud":
document.theform.box2.value = "to be ";
document.theform.box3.value = "an ";
document.theform.box4.value = "American";
break;

default: // don't ever say "I'll never hit this condition!!"
alert ("oops, box1 has an unknown value: " + document.theform.box1.value");
break;
} // switch (box1)

whammond
07-11-2002, 02:29 PM
Thank you very much, heres what I've done with your snippit:
-----------------------------------------------------------------------------------
<html>
<head>
<link rel=stylesheet type=text/css href='template.css'>
<title>Algorthm</title>
<script language="javascript">

switch (document.defaultext.textbox1.value) {
case "go":
document.defaultext.textbox2.value = "a";
document.defaultext.textbox3.value = "b";
document.defaultext.textbox4.value = "c";
break;

case "test":
document.defaultext.textbox2.value = "Larry";
document.defaultext.textbox3.value = "Moe";
document.defaultext.textbox4.value = "Curley";
break;

case "prod":
document.defaultext.textbox2.value = "to be ";
document.defaultext.textbox3.value = "an ";
document.defaultext.textbox4.value = "American";
break;

default:
alert ("oops, box1 has an unknown value: " + document.defaultext.textbox1.value);
break;
}
</script>


</head>

<body vspace=0 onLoad="document.defaultext.textbox1.onchange()">
<table width=630 bgcolor=#999966 align=left>
<tr height=20><td width="622">&nbsp;</td>
</tr><tr>
<td width="622">

<!-- code goes here -->


<table class=table align=center cellspacing=0 width=553>
<tr>
<td class=outTableTitle align=center colspan="2" width="535">
<center>Algorithm</center></td>
</tr>
<form method="POST" name="defaultext" action="">
<tr>
<td class=outTableHead width="60"> Text1 </td>
<td class=outTableText2 width="292">
<input type="text" name="textbox1" size="40"></td>
</tr><tr>
<td class=outTableHead width="60"> Text2 </td>
<td class=outTableText1 width="292">
<input type="text" name="textbox2" size="40"></td>
</tr><tr>
<td class=outTableHead width="60"> Text3 </td>
<td class=outTableText2 width="60">
<input type="text" name="textbox3" size="40"></td>
</tr><tr>
<td class=outTableHead width="60"> Text4 </td>
<td class=outTableText1 width="292">
<input type="text" name="textbox4" size="40"></td>
</tr>
</form>
</table>





<!--code ends here -->


</td>
<tr>
<td width="622">&nbsp;
</td>
</tr>
<tr height=300>
<td width="622">
</td></tr></table>

</body>
</html>
----------------------------------------------------------------------------------

I am still recieving an error...what am I doing wrong?:confused:

RadarBob
07-11-2002, 03:01 PM
Karnac we're not. What's the error message (or symptoms)?

1. you terminate your table just above the "code ends here" note. However you still use <tr> and <td> tags beyond that point. These need to be inside the table tags.

2. I think you need to add an "onchange" event handler for your textbox1 object, thus:

<input type="text" name="textbox1" size="40" onchange="forceValues(this.value)">

3. Make a function out of that code sample, thus:


function forceValues (textbox1Value) {
switch (texbox1Value) {
case "go":
... and so forth...
}
}

whammond
07-11-2002, 04:55 PM
The script with just a few small adjustments works perfectly.

:thumbsup:

THANK YOU SOOO MUCH FOR YOUR HELP!!!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum