/    Sign up×
Community /Pin to ProfileBookmark

multiple links to post

I have a tiny script that allows me to submit form via POST from a text link.

[code=php]
<script language=”JavaScript”>
<!–

function linkSubmit() {

document.myForm.submit();

}

//–>
</script>

<form name=”myForm” method=”post” action=”index.php”>

<input type=hidden name=tab value=”value1″>

</form>

<a href=”#” onClick=”linkSubmit(); return false;”>Link1</a>
[/code]

I need to add 4 more links but I do not want to duplicate forms and Javascript. Is it possible to make several links use the same script and form?

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@voidvectorNov 19.2008 — Not sure what you mean by "4 more links".

You can have duplicate links, but unless you change the javascript they would only perform the exact same operation.
Copy linkTweet thisAlerts:
@santaauthorNov 19.2008 — I'd like to be able to have 4 links all calling this function but each sending different variable.
Copy linkTweet thisAlerts:
@santaauthorNov 20.2008 — anyone?..
Copy linkTweet thisAlerts:
@MrNobodyNov 20.2008 — Sure, but what are you going to do with the parameter?

<a href="#" onClick="linkSubmit(1); return false;">Link1</a>

<a href="#" onClick="linkSubmit(2); return false;">Link1</a>

<a href="#" onClick="linkSubmit(3); return false;">Link1</a>

<a href="#" onClick="linkSubmit(4); return false;">Link1</a>
[CODE]function linkSubmit(num) {
alert(num);
document.myForm.submit();
}[/CODE]
×

Success!

Help @santa 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.5,
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,
)...