/    Sign up×
Community /Pin to ProfileBookmark

Fetching field value

Good Day,

I’m constructing a form field name on the fly:

var RulesFieldName = “document.asform.” + “Rulest3.value”;

The following two alerts show “document.asform.Rulest3.value”:
alert(RulesFieldName);
alert(RulesFieldName.valueOf());

I would like to fetch the value which is stored in this field.

Any ideas?

Thanks,
Dan

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@crh3675Jun 27.2005 — Your code is kind of buggy. Are you trying to get the value of the Rulest3 field to generate the name of a field that holds another value?

If that's the case, all you need is:

<i>
</i>var RulesFieldName = document.forms["asform"].Rulest3.value;
alert(RulesFieldName);
Copy linkTweet thisAlerts:
@Dan_DrillichauthorJun 27.2005 — Craig,

I'm trying to figure out what the name of the matching field is. For example:

<input type="text" name="CenterName" value="aa" >

<input type="hidden" name="RulesCenterName" value="t" >

When I iterate through the text fields, I would like to find out the value stored in the matching hidden field. So, in the above example, RulesCenterName matches the text CenterName field.

I hope it's clearer now.

-- Dan
Copy linkTweet thisAlerts:
@crh3675Jun 27.2005 — Oh, that's easy:

<i>
</i>&lt;form name="asform"&gt;
&lt;input type="text" name="CenterName" value="aa" &gt;
&lt;input type="hidden" name="RulesCenterName" value="t" &gt;

&lt;input type="button" onclick="soitbe()"&gt;
&lt;/form&gt;


&lt;script&gt;
function soitbe(){
var f=document.forms['asform'];
var fld=f.CenterName;
var fldVal1=fld.value;
var fldVal2="";

<i> </i>for(i=0;i&lt;f.elements.length;i++){
<i> </i> var regexp=eval("/"+fld.name+"$/");
<i> </i> if(f.elements[i].name.match(regexp) &amp;&amp; f.elements[i].name!=fld.name){
<i> </i> fldVal2=f.elements[i].value;
<i> </i> break;
<i> </i> }
<i> </i>}
<i> </i>alert(fldVal1+":"+fldVal2)
}
&lt;/script&gt;
Copy linkTweet thisAlerts:
@Dan_DrillichauthorJun 27.2005 — Thank You Craig!

Based on your previous advice I got the following to work:

alert(document.forms[fName].elements["Rules" + element.name].value);

-- Dan
×

Success!

Help @Dan_Drillich spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.3,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...