Gossamer Forum
Home : General : Internet Technologies :

JavaScript Auto Fill Help Needed.

Quote Reply
JavaScript Auto Fill Help Needed.
Please Help with following code.
works in Netscape but not IE.

eval() not used correctly!

Code:
function AutoFill(FormName,SelectName,TargetName) {
var v = document.eval(FormName).eval(SelectName).selectedIndex;
var Output = document.eval(FormName).eval(SelectName).options[v].text;
if (Output > 1){
document.eval(FormName).eval(TargetName).value = "Yes"
}
else if (Output == "---") {
document.eval(FormName).eval(TargetName).value = "No"
}
else {
document.eval(FormName).eval(TargetName).value = "No"
}
}


<form name="MyForm">
<input name="MyInput" type="text" size="10">
<select name="MySelect" onchange="AutoFill('MyForm','Myselect','MyInput')">
<option>---
<option>1
<option>2
<option>3
</select>
</form>

Basically, what is the correct coding for:
Code:
document.eval(FormName).eval(SelectName).selectedIndex

I know that eval() is not the correct way to code this but I haven't been able to figure out the correct way.

Thanks,
beetlemanTongue

Marcus L. Griswold

Last edited by:

beetleman: Mar 28, 2003, 4:50 AM
Quote Reply
Re: [beetleman] JavaScript Auto Fill Help Needed. In reply to
I use a couple of "auto-fill" scripts... what is your ultimate purpose?
Quote Reply
Re: [Watts] JavaScript Auto Fill Help Needed. In reply to
Hi Watts,

Thanks for the reply.

I found the answer at a JavaScript Forum.
The Finished Script:
Code:
function AutoFill(InputType,FormName,InputName,Argument,ConTrue,ConFalse,TargetName,FunctionTwo) {
if (FunctionTwo == "add") {
NewOption(FormName,InputName);
}
if (InputType == "select") {
var Output = document.forms[FormName].elements[InputName].options[document.forms[FormName].elements[InputName].selectedIndex].text;
}
else if (InputType == "text") {
var Output = document.forms[FormName].elements[InputName].value;
}
else {
var Output = "Error";
}
if (eval(Argument)){
document.forms[FormName].elements[TargetName].value = ConTrue;
}
else {
document.forms[FormName].elements[TargetName].value = ConFalse;
}
}

And The Call:
Code:
<INPUT TYPE="TEXT" NAME="FieldName1" VALUE="$rec{'FieldName1'}" SIZE="20" maxlength="255" onblur=\"AutoFill('text',this.form.name,this.name,'Output \\!\\= \\'\\'','Yes','No','FieldName2')\">

I had had trouble with:
Code:
document.forms[FormName].elements[TargetName].value = ConFalse;
because I was using "this.form" instead of "this.form.name"

Basically, the script is used to autofill hidden fields based on user input.
This particular call changes FieldName2 to "Yes" if FieldName1 is filled in. As a result, during searches of the database, the user can search to see records that have anything in the FieldName1 field.

As there are many of these autofill areas on my add record page, I didn't want to write a custom script for each one.
This script is completely dependent on the arguments in the call to determine output.

By the way, the script and call are nestled in to an html perl pl template thus all of the extra "\".

If you would like to use the script, let me know and I'll clean it up for general use.

Thanks again for the reply.
beetlemanTongue

Marcus L. Griswold