/    Sign up×
Community /Pin to ProfileBookmark

Convert submit button in <a> tag

Hello Friends

I want to convert my submit button code to hyperlink code
can anybody help me as soon
for example my code like this –

<form name=”email” method=”POST” action=”SendChart.jsp” onSubmit=”return TestDataCheck()”>




<tr>
<td><BR><input type=”submit” value=”Send Mail” name=”post” /></td></tr>

Please help me to convert button to simple hyperlink using <a></a>

Regard
RK

to post a comment
JavaScript

7 Comments(s)

Copy linkTweet thisAlerts:
@KorSep 30.2008 — Why a hyperlink? That will spoil the submit action. If you need a custom submit button, you may use either the BUTTON tag (<button type="submit"...></button>) or an image input (<input type="image" src="" />).

But... What that has to do with javascript, after all?
Copy linkTweet thisAlerts:
@Kostas_ZotosSep 30.2008 — Hi,

Maybe something like this?

<form name="email" [B]id="email"[/B] method="POST" action="SendChart.jsp" onSubmit="return TestDataCheck()">


---

--
--


<tr>

<td><BR>

[B]<a href="javascript: document.getElementById('email').submit()" title="Submit form">Submit Form</a>[/B]

</td></tr>

Kostas
Copy linkTweet thisAlerts:
@rajiv_birariauthorSep 30.2008 — Why a hyperlink? That will spoil the submit action. If you need a custom submit button, you may use either the BUTTON tag (<button type="submit"...></button>) or an image input (<input type="image" src="" />).

But... What that has to do with javascript, after all?[/QUOTE]


Hello Kor,

I required hyperlink becz I can't show button on mobile screen

I want convert some pages for mobile views.
Copy linkTweet thisAlerts:
@Kostas_ZotosSep 30.2008 — Hi,

My previous code bypass the form check [ "TestDataCheck()"]

so you may combine the submit and check in one entity, eg like this:

[CODE]<html>

<head>
<title>Submit as Link</title>

<script language="javascript" type="text/javascript">

function TestDataCheck() {

var checkFlag =true [B]// YOUR CHECK VALUE HERE (true OR false) (AS DERIVED FROM YOUR VALIDATION CODE)[/B]
if (checkFlag){
document.getElementById('email').[B]submit()[/B] // Send the form (if pass the validation)
} else{
alert("Invalid input data nn Please retry")

}
return checkFlag

}

</script>

</head>


<body>
<form name="email" [B]id="email"[/B] method="POST" [B]target="_blank"[/B] action="SendChart.jsp">

<table>
<tr>
<td>
<!-- input type="submit" value="Send Mail" name="post" / -->
[B]<a href="javascript: TestDataCheck();void(0)" title="Submit form" >Submit Form</a>[/B]

</td>
</tr>
</table>

</form>

</body>
</html>[/CODE]


Kostas
Copy linkTweet thisAlerts:
@KorSep 30.2008 — 
[B]<a href="javascript:document.getElementById('email').submit()" title="Submit form">Submit Form</a>[/B]
[/QUOTE]

Correct, but there is no need for the token [B]javascript:[/B]. The common modern standard way is to use events for launching functions or statements:
<i>
</i>&lt;a href="#" onclick="document.getElementById('email').submit();return false" title="Submit form"&gt;Submit Form&lt;/a&gt;
Copy linkTweet thisAlerts:
@Kostas_ZotosSep 30.2008 — Thanks Kor ?
Copy linkTweet thisAlerts:
@Kostas_ZotosSep 30.2008 — Just to add an alternative code that is more close to your initial form construction:

No need to combine the submit and check in this variation, (in the way suggested in my last -previous- post)

This uses the "TestDataCheck()" inside the <a> tag and if the check returns true, then send the form, otherwise not.

Note:This approach requires that the "TestDataCheck()" function returns true or false


[CODE]<form name="email" [B]id="email"[/B] method="POST" [B]target="_blank"[/B] action="SendChart.jsp">

<table>
<tr>
<td>
<!-- input type="submit" value="Send Mail" name="post" / -->

<!-- The next suggestions require that the "TestDataCheck()" returns true or false -->
[B]<a href="javascript: if(TestDataCheck()) document.getElementById('email').submit(); void(0)" title="Submit form" >Submit Form</a>[/B]

// Or as Kor stated:
<a href="#" onclick="if (TestDataCheck()) document.getElementById('email').submit(); void(0)" title="Submit form" >Submit Form</a>

</td>
</tr>
</table>

</form>[/CODE]


Kostas
×

Success!

Help @rajiv_birari 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.18,
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,
)...