/    Sign up×
Community /Pin to ProfileBookmark

Initialize value from variable

Newbie here.

I could not find the syntax how to set initial value here:

[CODE]
var [COLOR=”red”]indat [/COLOR]= window.clipboardData.getData (“Text”);
.
.
.
.
.
<input type=”text” name=”q” value= xxxxxx size=”40″ />[/CODE]

I would like the value to be the indat var value

I saw lot of samples with value=”aaaaa” (hard coded value) but could not find sample for var value

thanks for help !!

to post a comment
HTML

2 Comments(s)

Copy linkTweet thisAlerts:
@wwwapprenticeMay 11.2011 — Normally you set the default value like this;

[code=html]Year: <input type="text" name="year" id="year" value="2011" />[/code]

But when you want some variable to be at that place, you are already busy with javascript. Javascript can of course edit the value attribute. So you simply set the value in the code itself.

Here's a full example, although I didn't specify a value hardcoded, javascript will fill it in for me. I 've wrapped it in an onload so that it executes when everything is ready.

[code=html]<html>
<head>
<title>This year example</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript">
window.onload = function(){
document.getElementById("year").value = 2011;
};
</script>
</head>
<body>
Year: <input type="text" name="year" id="year" />
</body>
</html>[/code]


And then of course you can easily change the value into something variable, like the actual year. ?

Let me know if this helped!

grtz

wwwapprentice
Copy linkTweet thisAlerts:
@gonenauthorMay 11.2011 — thanks !!!

Sure will try !!
×

Success!

Help @gonen 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.16,
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: @nearjob,
tipped: article
amount: 1000 SATS,

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

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