variable form submit

G

google

i have a page that has multipe forms that do almost the same thing but
just to diffrent database entrys. i want a "are you sure?" button to
come up when the submit button is pressed and if ok is pressed then
that from to be submited.currently i have
function disp_confirm(id)
{
var r=confirm("Are you sure you want to delete it?");
if (r==true)
{
document.getElementById(id).submit()
}
}

<form name="<%=id%>" id="<%=id%>" action="submitpage.asp"
method="post">
<input type="hidden" name="id" value="<%=id%>">
<tr>
<td><%=text%></td>
<td><%=text2%></td>
<td><input type="button" value="delete" onClick="disp_confirm(<%=id
%>)"></td>
</tr>
</form>


can anyone give me some pointers please?
 
E

Evertjan.

wrote on 21 jan 2008 in comp.lang.javascript:
i have a page that has multipe forms that do almost the same thing but
just to diffrent database entrys. i want a "are you sure?" button to
come up when the submit button is pressed and if ok is pressed then
that from to be submited.currently i have
function disp_confirm(id)
{
var r=confirm("Are you sure you want to delete it?");
if (r==true)

(r==true) acts the same as (r)
{
document.getElementById(id).submit()
}
}

Waw!, are you in need of superfluous code parts?
<form name="<%=id%>" id="<%=id%>" action="submitpage.asp"
method="post">
<input type="hidden" name="id" value="<%=id%>">
<tr>
<td><%=text%></td>
<td><%=text2%></td>
<td><input type="button" value="delete"
onClick="disp_confirm(<%=id
%>)">

Use the onsubmit in the <form>


do not include code that has nothing to do with the Q.

Try:

=============================
<script type='text/javascript'>
function disp_confirm(id) {
if (confirm("Are you sure you want to delete it?"))
document.getElementById(id).submit();
};
</script>

<form action="submitpage.asp" id="<%=id%>" method="post">
<input type="hidden" name="id" value="<%=id%>">
<input type="button" value="delete"
onClick="disp_confirm(<%=id%>)">
</form>
=============================

or better, [if you are sure the user has javascropt on]:

=============================
<script type='text/javascript'>
function disp_confirm() {
return (confirm("Are you sure you want to delete it?"));
};
</script>

<form action="submitpage.asp" method="post"
onsubmit="return disp_confirm()">
<input type="hidden" name="id" value="<%=id%>">
<input type="submit" value="delete">
</form>
=============================

or better imho:

=============================
<form action="submitpage.asp" method="post"
onsubmit="return confirm('Are you sure you want to delete it?');">
<input type="hidden" name="id" value="<%=id%>">
<input type="submit" value="delete">
</form>
=============================

or if you want a general text for multiple forms:

=============================
<script type='text/javascript'>
var confirmText = 'Are you sure you want to delete it?';
</script>

<form action="submitpage.asp" method="post"
onsubmit="return confirm(confirmText);">
<input type="hidden" name="id" value="<%=id%>">
<input type="submit" value="delete">
</form>
=============================
 
A

Anjoe13

I found a problem as below ...
<input type="button" value="delete" onClick="disp_confirm(<%=id%>)">

It should be ...
<input type="button" value="delete" onClick="disp_confirm(\"<%=id%>
\")">
or
<input type="button" value="delete" onClick="disp_confirm('<%=id%>')">

If not, there will be an errors at least. The reasons are ...
A. When "onClick()", "disp_confirm()" doesn't know what "id" is. It
might tell you "undefined".
B.There'll be problem in "disp_confirm()" that "id" in
"document.getElementById()" should be a string value.

That's what I found. Hope it helpful.
 
G

google

thanks all Anjoe13 got the solution i was trying to find but couldnt
think of it. ill take your comments into mind with my next project.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,280
Latest member
BGBBrock56

Latest Threads

Top