/    Sign up×
Community /Pin to ProfileBookmark

Calling a variable in a html form

I am trying to call a javascript variable into an html form so I can email it.

This code gets a variable from the URL called “DistId”.

[code]
//Gets DistID from URL
var query = window.location.search;
// Skip the leading ?, which should always be there,
// but be careful anyway
if (query.substring(0, 1) == ‘?’) {
query = query.substring(1);
}
var DistID = query.split(‘,’);
for (i = 0; (i < data.length); i++) {
DistID[i] = unescape(data[i]);
}
[/code]

What I need to do is figure out how to call “DistId”. I am attempting to go about by using the following. But of course, I am just getting the literal and not the variable.

[code]
<!—Trying to get variable DistID to be sent in email–>
<input type=”hidden” name=”Dist ID” value=’DistID’>
[/code]

Any suggestions about calling it or know another way of getting the variable into the email?

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@steveaAug 02.2007 — <i>
</i>window.onload = function(){
try{document.getElementById('DistID').setAttribute('value',DistID);}
catch(e){
//Just to be safe, incase setAttribute didn't work
document.getElementById('DistID').value = DistID;
}
}


This will set the value when the page loads up (assuming of course you: give the field an id AND name, and setup the onload inside of the function that contains the definition of DistID).

Hope that helps
Copy linkTweet thisAlerts:
@RuthdaWebbieauthorAug 04.2007 — Thanks! ?
Copy linkTweet thisAlerts:
@KorAug 04.2007 — <i>
</i>//Just to be safe, incase setAttribute didn't work

[/QUOTE]


Yes, but the DOM 0 syntax

[I]element[/I].[COLOR="Navy"]HTMLattribute[/COLOR]=[I]value[/I]

works always (well, almost :rolleyes: ), thus I see is no reason for using setAttribute() in this case...
×

Success!

Help @RuthdaWebbie 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 6.2,
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: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

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