/    Sign up×
Community /Pin to ProfileBookmark

Insert data to page

I know how to pass data to a form field from eg. a image.

But how do you insert data to a form field after klicking on a image in another page?

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@nap0leonDec 13.2007 — Depending on the language your page is written in and what the link on the image that is clicked is... there's tons of ways and JavaScript might not be the best choice.

Let's call your pages "page1" and "page2".

Let's presume page1 has two buttons ("button1" and "button2") on it that both link to page2.

If the user clicks on button1, you want a field on page2 to say "Alpha".

If the user clicks on button2, you want a field on page2 to say "Beta".

Your images on page1 need some way to tell page2 what the user clicked.

For my example, I will presume you are passing the value in the URL, this could be changed to be a form-field value or session variable, etc.

So, on page1, your images would look like
[CODE]
<a href="page2.asp?choice=Alpha"><img src="button1.gif"></a>
<a href="page2.asp?choice=Beta"><img src="button2.gif"></a>
[/CODE]


If you want to set the value using Classic ASP...
[CODE]
<input type=text id="Choice" value="<%=Request.QueryString("choice")" />
[/CODE]


In JavaScript it's a tad more complex. This presumes that "choice" will always be the first item in the URL and your form's name is "form1".
[CODE]
<input type=text id="txtChoice" value="" />

<script>
var Choice = document.location.search.substring(1).split('=')[1];
document.form1.box1.value = Choice
<script>
[/CODE]
Copy linkTweet thisAlerts:
@nap0leonDec 13.2007 — Or... are you looking for something like this:

You have a field on a page and when an image is clicked you want that field to now have a value?

[CODE]
<input type="text" name="field1" value="" />
<img src="button1.gif" onClick="javascript:UpdateField1('Button One Clicked') />
<img src="button2.gif" onClick="javascript:UpdateField1('Button Two Clicked') />

<script>
function UpdateField1(fieldvalue){
document.form1.field1.value=fieldvalue;
}
</script>
[/CODE]
×

Success!

Help @alxla 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.25,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

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

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