How to use form value as variable ============

R

Ray Muforosky

// I have:

aval = document.form1.field1.value

// I want to do this:

bval = document.form1.aval.value // that is

bval = document.form1.[document.form1.field1.value].value

//any help or input on how to this correct will be appreciated.

//Ray
 
I

Ivo

// I have:

aval = document.form1.field1.value

// I want to do this:

bval = document.form1.aval.value // that is

bval = document.form1.[document.form1.field1.value].value
You 're almost there. I think if you remove the dot before the opening
square bracket and the form values are what you expect, it should behave
correctly.
See the FAQ:
<URL: http://jibbering.com/faq/#FAQ4_39 >

HTH
Ivo
 
H

Hywel

Ray Muforosky said:
// I have:



// I want to do this:

bval = document.form1.aval.value // that is

bval = document.form1.[document.form1.field1.value].value

Try
aval = document.form1.field1.value;
bval = document.form1[aval].value;

I haven't tested it.
 
T

Thomas 'PointedEars' Lahn

Hywel said:
[...] Ray Muforosky says...
// I want to do this:

bval = document.form1.aval.value // that is

bval = document.form1.[document.form1.field1.value].value

Try
aval = document.form1.field1.value;
bval = document.form1[aval].value;

I haven't tested it.

Should be (standards compliant and downwards compatible)

bval = document.forms['form1'].elements[aval].value;

(See FAQ entry 4.13.)


PointedEars
 
R

Ray Muforosky

HELP HELP HELP
document.form1.calnote
=============
<form action="cmdlog_update.pl" name="f1" onSubmit='return
validateT();'>
<P><STRONG>Username<INPUT type="text" tabindex="0" name="username"></P>
<P><STRONG>Row Num.<INPUT READONLY type="text" name="rownum" ></P>
<p><textarea rows="4" name="calnote" cols="50">Enter your note here,
200 characters max. </textarea>
<p><INPUT TYPE="submit" value="Update" action="">
Change Launch Note Status?<INPUT TYPE="checkbox" NAME="lnote"
onClick='alert(lnote_msg);' VALUE= "LNCHNOTE"
-------cut------

document.outform.["z" + the value of radio_1] or
document.outform.["z" + this.value]
//
============================================
<TD nowrap><INPUT TYPE="RADIO" NAME="radio_1" VALUE=50198
onClick='document.getElementById("form1").style.display="";
document.f1.rownum.value=this.value;
aval = this.value;
bval = "z" + aval;

document.f1.calnote.value=document.forms[outform].elements[bval].value;
document.f1.username.focus()' >50198 </TD>
<TD nowrap> log </TD>
<TD nowrap> 2004-08-13 </TD>
<TD nowrap> 12:00:00 </TD>
<TD nowrap> rmuforo </TD>
<TD nowrap> PERMISSION </TD>
<TD nowrap> INST-RCD </TD>
<TD nowrap><INPUT READONLY TYPE="TEXT" SIZE="35" MAXLENGT="400"
VALUE="Enter your note here testing eval" name="z50198"
onClick='document.f1.calnote.value=this.value;'></TD><TD
nowrap><INPUT READONLY TYPE="TEXT" SIZE="35" MAXLENGT="400"
VALUE="\N
"></TD></TR>
-------cut------
=============================================
I want to send the value of z50198 which is
document.outform.z50198.value to
document.form1.calnote.value

I cannot hardcode z50198 it changes.
how can I do this
 
R

Ray Muforosky

thanks Ivo for the clue.

aval = this.value;
bval = \"z\" + aval;

document.f1.calnote.value=document.outform.elements[bval].value;

it works now
 
T

Thomas 'PointedEars' Lahn

Ray said:
thanks Ivo for the clue.

aval = this.value;
bval = \"z\" + aval; ^ ^
document.f1.calnote.value=document.outform.elements[bval].value;

it works now

That's highly unlikely. Besides, the code is inefficient and
referencing is still proprietary (despite previous examples!):

var fs = document.forms;
fs['f1'].elements['calnote'].value =
fs['outform'].elements["z" + this.value].value;


PointedEars
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,066
Latest member
VytoKetoReviews

Latest Threads

Top