473,372 Members | 1,113 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,372 software developers and data experts.

return value from a function calles inside submit()

Hi,

Some place I use links to submit forms instead of a submit button. The
way I have done this is: <a
href="javascript:document.getElementById('<?php print "delete$i"
;?>').submit()>Delete?</a>.
This method worked perfectly fine. But then I also wanted to add a confirm
box to the user where. A confirm("do you really want to delete?").
So I made the function:
function controll()
{
if(confirm("Do you really want to delete?"))
{
return (true);
}
else
{
return (false);
}
}
And tried to call the function from inside the submit() like
<a href="javascript:document.getElementById('<?php print "delete$i"
;?>').submit(controll())>Delete?</a>.
This also works fine, but then I have to return the return value. So i
tried
<a href="javascript:document.getElementById('<?php print "delete$i"
;?>').submit(return controll())>Delete?</a>.
And that does not work.
It does work inside the onSubmit="..." then.
So My question is: How could I both use a link inside a form and give the
user the opportunity to regret the choice?
Sindre
Jul 23 '05 #1
7 1970
sindre <si******@c2i.net> wrote in message news:<opsaf5i9rcxg0aby@xn--sindres_brbare-8ib>...
Hi,

Some place I use links to submit forms instead of a submit button. The
way I have done this is: <a
href="javascript:document.getElementById('<?php print "delete$i"
;?>').submit()>Delete?</a>.
This method worked perfectly fine. But then I also wanted to add a confirm
box to the user where. A confirm("do you really want to delete?").
So I made the function:
function controll()
{
if(confirm("Do you really want to delete?"))
{
return (true);
}
else
{
return (false);
}
}
And tried to call the function from inside the submit() like
<a href="javascript:document.getElementById('<?php print "delete$i"
;?>').submit(controll())>Delete?</a>.
This also works fine, but then I have to return the return value. So i
tried
<a href="javascript:document.getElementById('<?php print "delete$i"
;?>').submit(return controll())>Delete?</a>.
And that does not work.
It does work inside the onSubmit="..." then.
So My question is: How could I both use a link inside a form and give the
user the opportunity to regret the choice?
Sindre


Hi Sindre,

Why don't you just use a <p> or <span> or <div> for your link?
I'd do it this way:

<script type="text/javascript">
function conditional_submit (myForm) {
if(confirm("Do you really want to delete?")) {
document.myForm.submit();
} else {
//nothing to do
}
}
</script>

<p onclick="conditional_submit(document.getElementByI d('<?php print
"delete$i";?>')">Delete?</p>

I didn't test it, but I hope it works. You could combine it with an
image too.
HTH

cu, Michael
Jul 23 '05 #2
sindre <si******@c2i.net> wrote in message news:<opsaf5i9rcxg0aby@xn--sindres_brbare-8ib>...
Hi,

Some place I use links to submit forms instead of a submit button. The
way I have done this is: <a
href="javascript:document.getElementById('<?php print "delete$i"
;?>').submit()>Delete?</a>.
....

you can try:

href="javascript:if(confirm('Do you really want to
delete?'))document.getElementById('<?php print "delete$i" ;?>').submit()">Delete</a>


cheers,
mortb
Jul 23 '05 #3
Why don't you just use a <p> or <span> or <div> for your link?
I'd do it this way:

<script type="text/javascript">
function conditional_submit (myForm) {
if(confirm("Do you really want to delete?")) {
document.myForm.submit();
} else {
//nothing to do
}
}
</script>

<p onclick="conditional_submit(document.getElementByI d('<?php print
"delete$i";?>')">Delete?</p>


Actually it dont. Firstly onclick in div, p og span is not supported by
netscape 6.x. But it wont work either in opera or explorer. Nothing
happens when i move the mouse over the "link" and nothing happens when i
click the word.

Sindre
Jul 23 '05 #4
sindre <si******@c2i.net> wrote in message news:<opsahzcwnbxg0aby@xn--sindres_brbare-8ib>...
Why don't you just use a <p> or <span> or <div> for your link?
I'd do it this way:

<script type="text/javascript">
function conditional_submit (myForm) {
if(confirm("Do you really want to delete?")) {
document.myForm.submit();
} else {

//nothing to do
}
}
</script>

<p onclick="conditional_submit(document.getElementByI d('<?php print
"delete$i";?>')">Delete?</p>


Actually it dont. Firstly onclick in div, p og span is not supported by
netscape 6.x. But it wont work either in opera or explorer. Nothing
happens when i move the mouse over the "link" and nothing happens when i
click the word.

Sindre


Sorry, my mistake. I forgot a closing bracket and it should be
myForm.submit(); instead of document.myForm.submit().

Here is an complete example-page, that workes out in Mozilla 1.7,
Netscape 6.2 and IE 6. It does not work in NS 4.75, because this one
does not jet support getElementById. I substituted '<?php print
"delete$i";?>' with 'delete1' in my example. As mortb wrote, you can
place the code of the function in the onclick event directly, depends
on how many forms you have in your page. You could also just send the
name(text!) of the form to the function like
onclick="conditional_submit('delete1');", then, depending on the
browser you could use document.getElementsByName,
document.getElementById or even document.all to get your form-object.

!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN">
<html>
<head>
<title>tests</title>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-15">

<script type="text/javascript">
function conditional_submit (myForm) { if(confirm("Do you really want
to delete?")) myForm.submit() }
</script>

<body>

<p onclick="conditional_submit(document.getElementByI d('delete1'))"
style="cursor:pointer">Delete?</p>
<br>
<div onclick="conditional_submit(document.getElementByI d('delete1'))"
style="cursor:pointer">Delete?</div>
<br>
<span onclick="conditional_submit(document.getElementByI d('delete1'))"
style="cursor:pointer">Delete?</span>
<br><br>
<a href="#" onclick="conditional_submit(document.getElementByI d('delete1'));return(false);">Delete?</a>
<br><br>
<a href=javascript:conditional_submit(document.getEle mentById('delete1'));>Delete?</a>
<br><br><form name="delete1" id="delete1" action="if1.html"
method="get" target="_self">
<input type="text" size="20" maxlength="30" name="myText">

</form>

</body>
</html>

Recommendation: Use CSS to format the links

cu, Michael
Jul 23 '05 #5
!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN">
<html>
<head>
<title>tests</title>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-15">

<script type="text/javascript">
function conditional_submit (myForm) { if(confirm("Do you really want
to delete?")) myForm.submit() }
</script>

<body>

<p onclick="conditional_submit(document.getElementByI d('delete1'))"
style="cursor:pointer">Delete?</p>
<br>
<div onclick="conditional_submit(document.getElementByI d('delete1'))"
style="cursor:pointer">Delete?</div>
<br>
<span onclick="conditional_submit(document.getElementByI d('delete1'))"
style="cursor:pointer">Delete?</span>
<br><br>
<a href="#"
onclick="conditional_submit(document.getElementByI d('delete1'));return(false);">Delete?</a>
<br><br>
<a
href=javascript:conditional_submit(document.getEle mentById('delete1'));>Delete?</a>
<br><br><form name="delete1" id="delete1" action="if1.html"
method="get" target="_self">
<input type="text" size="20" maxlength="30" name="myText">

</form>

</body>
</html>

Recommendation: Use CSS to format the links

cu, Michael


Sorry,
But It did not work. I used cut and paste the whole section. None of the
links worked here:-)

Sindre

--
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
Jul 23 '05 #6
sindre wrote:
!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN">
<html>
<head>
<title>tests</title>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-15">

<script type="text/javascript">
function conditional_submit (myForm) { if(confirm("Do you really want
to delete?")) myForm.submit() }
</script>

<body>

<p onclick="conditional_submit(document.getElementByI d('delete1'))"
style="cursor:pointer">Delete?</p>
<br>
<div onclick="conditional_submit(document.getElementByI d('delete1'))"
style="cursor:pointer">Delete?</div>
<br>
<span onclick="conditional_submit(document.getElementByI d('delete1'))"
style="cursor:pointer">Delete?</span>
<br><br>
<a href="#"
onclick="conditional_submit(document.getElementByI d('delete1'));return(false);">Delete?</a>
<br><br>
<a
href=javascript:conditional_submit(document.getEle mentById('delete1'));>Delete?</a>
<br><br><form name="delete1" id="delete1" action="if1.html"
method="get" target="_self">
<input type="text" size="20" maxlength="30" name="myText">

</form>

</body>
</html>

Recommendation: Use CSS to format the links

cu, Michael
Sorry,
But It did not work. I used cut and paste the whole section. None of the
links worked here:-)

Sindre


If you copied and pasted it verbatim, then the call to "confirm()" probably wrapped, which would
have resulted in a syntax error.

I just tested the code (after cleaning it up a bit) and it works fine:

<html>
<head>
<script type="text/javascript">
function confirm_delete(theForm) {
// DO NOT LET THE NEXT LINE WRAP
if (confirm("Do you really want to delete?")) {
theForm.submit();
}
}
</script>
</head>
<body>

&lt;P>:
<p
onclick="confirm_delete(document.forms['delete1']);"
style="cursor:pointer;"Delete?</p>
&lt;DIV>:
<div
onclick="confirm_delete(document.forms['delete1']);"
style="cursor:pointer;"Delete?</div>
<br>

&lt;SPAN>:
<span
onclick="confirm_delete(document.forms['delete1']);"
style="cursor:pointer;"Delete?</span>
<br>
<br>

&lt;A>:
<a
href="#"
onclick="
confirm_delete(document.forms['delete1']);
return false;
"Delete?</a>


<br><br>

<form name="delete1" action="action.cgi" method="get">
<input type="text" size="20" name="myText">
</form>
</body>
</html>

Everything is split across multiple lines to try make it clearer and to try to avoid
inappropriate line breaks caused by your news reader software.

--
| Grant Wagner <gw*****@agricoreunited.com>

* Client-side Javascript and Netscape 4 DOM Reference available at:
* http://devedge.netscape.com/library/...ce/frames.html
* Internet Explorer DOM Reference available at:
* http://msdn.microsoft.com/workshop/a...ence_entry.asp
* Netscape 6/7 DOM Reference available at:
* http://www.mozilla.org/docs/dom/domref/
* Tips for upgrading JavaScript for Netscape 7 / Mozilla
* http://www.mozilla.org/docs/web-deve...upgrade_2.html
Jul 23 '05 #7
Grant Wagner wrote:
If you copied and pasted it verbatim, then the call to "confirm()" probably wrapped, which would
have resulted in a syntax error.

| Grant Wagner <gw*****@agricoreunited.com>


I used the Web-Interface of google, which is breaking the lines. I
changed to my mail/news client, so this should not happen anymore.
Jul 23 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: lawrence | last post by:
I've this function, which is the method of a class. I'm posting the constructor of the class down below. For some reason, when I fill out a form and hit submit, I'm not getting any values. Can...
3
by: Varun | last post by:
Hi There, I have a form("myRequest.asp") and the values from it are retrieved into the page ("output_Print.asp") on which I have two buttons('Save As Complete' and 'Save As Incomplete'). When the...
4
by: Roger Withnell | last post by:
I want to validate the data entered into a form text field by calling a function with onblur, doing the validation and, if the input is invalid, giving an alert to the user and returning focus and...
1
by: Piotr | last post by:
I have popup window (window.open) where I put any value in input field. After submit I wan to to return to the main window and get value from popup window. How to close popup window and return to...
12
by: Mike Brashars | last post by:
Hi all, I have been searching for a week and am unable to find and example to "Populate picklist from directory and return file name". I have a php script that reads a log file and plots a...
4
by: ACaunter | last post by:
Hi there, Is there a way to call a javascript function and return its value, from inside an asp.net button ?? -- AdamPC@hotmail.com
5
by: siaj | last post by:
Hello, I have a javascript function for a validation in the HTML page of the asp.Net page.. I call this function in a Savebutton click When the validation fails No postback should happen ( ie...
13
by: kurtj | last post by:
Hello Gurus: I have a validation script (below) that is somehow messed up. If the Name field is blank, I get the alert message, then the browser window goes to a blank document with the word...
13
by: Steve | last post by:
On page 392 of "Javascript the definitive guide" a function is called like this:- <form action="processform.cgi" onsubmit="return validateForm();"> Why, in this instance, is the return...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.