|
-
Oct 6th, 2006, 11:30 PM
#1
Thread Starter
Addicted Member
How to disable button in action
Hello
Take a look at this code
PHP Code:
<?php
if ($v == "1") {
--"ACTIONS WHICH I WANT TO DO"--
exit();
}
echo "<form action=file.php method=post>";
echo "<input type=hidden name=v value=1>";
echo "<input type=submit value=Go>";
echo "</form>";
?>
What I want how can I disable the button "Go" after I'd clicked on it.
I know it needs JS, how can I do it by JS?
-
Oct 7th, 2006, 12:11 AM
#2
Re: How to disable button in action
This is what you're looking for.
-
Oct 7th, 2006, 12:30 AM
#3
Thread Starter
Addicted Member
Re: How to disable button in action
I saved it as "html" and it didn't work.
After I'd clicked on the button, nothing happends.
-
Oct 7th, 2006, 12:41 AM
#4
Re: How to disable button in action
the script works fine, there's a demo on the site... if you didn't set it up correctly, then it isn't going to work. make sure you read the comments given to set it up correctly...
-
Oct 7th, 2006, 12:16 PM
#5
Thread Starter
Addicted Member
Re: How to disable button in action
I don't know how to program JS well.
Can you set it up for me?
-
Oct 7th, 2006, 03:28 PM
#6
Re: How to disable button in action
..? there is no setting up.. all you need to do is read and follow the directions, you don't need to know javascript. all of the code is aleady given to you. there's nothing to change. if you have a submit button you will have a form that it is contained in. add the onSubmit parameter to that form, just like in the code given to you, and add the rest of the code at the top of your page.
-
Oct 7th, 2006, 03:33 PM
#7
Thread Starter
Addicted Member
Re: How to disable button in action
I pasted it in FrontPage, I saved it, I previewed it then I clicked on the submit button, nothing happends.
-
Oct 7th, 2006, 03:56 PM
#8
Re: How to disable button in action
I don't use FrontPage, and never have, so I don't know what you're doing wrong... post your code if you can't get it working :/
-
Oct 7th, 2006, 03:59 PM
#9
Thread Starter
Addicted Member
Re: How to disable button in action
I used that code which in the website, but I saved it as "html" file.
-
Oct 7th, 2006, 04:00 PM
#10
Re: How to disable button in action
It doesn't matter if you saved it as an HTML file, that's what you're supposed to do. The code works fine, so if it isn't working in FrontPage for you, then I don't know what to tell you, because I don't use it and don't know what it might do.
Try pasting it into Notepad and saving it as an HTML file and open it in IE.
-
Oct 7th, 2006, 04:05 PM
#11
Thread Starter
Addicted Member
Re: How to disable button in action
But it couldn't show the message (alert).
-
Oct 7th, 2006, 04:27 PM
#12
Re: How to disable button in action
if the demo on the site I gave you displayed the alert and your version didn't, then what did you change?
if the demo on the site didn't display an alert, then you have an out-of-date browser.
I checked, and the script works as expected in the latest versions of FireFox, IE7 Beta/IE6, and Opera.
-
Oct 7th, 2006, 05:07 PM
#13
Thread Starter
Addicted Member
Re: How to disable button in action
I have IE 6.0
OK I don't want to show alert; I just want when I click on the submit button, the button disables and going to another website.
-
Oct 7th, 2006, 08:09 PM
#14
Re: How to disable button in action
then just take the alerts out. the rest of the code will still work.
-
Oct 7th, 2006, 08:45 PM
#15
Thread Starter
Addicted Member
Re: How to disable button in action
I want to save it as PHP, look what I wrote:
PHP Code:
<?php
echo "<form onSubmit=\"return disableForm(this);\">";
echo "Name: <input type=text name=person>";
echo "<input type=submit><input type=reset>";
echo "</form>";
?>
<html>
<head>
<SCRIPT LANGUAGE="JavaScript">
function disableForm(theform) {
if (document.all || document.getElementById) {
for (i = 0; i < theform.length; i++) {
var tempobj = theform.elements[i];
if (tempobj.type.toLowerCase() == "submit" || tempobj.type.toLowerCase() == "reset")
tempobj.disabled = true;
}
document.write ($person);
return true;
}
else {
alert("The form has been submitted. But, since you're not using IE 4+ or NS 6, the submit button was not disabled on form submission.");
return false;
</script>
</head>
</html>
But it didn't work.
It couldn't output $person.
Why please?
-
Oct 7th, 2006, 09:59 PM
#16
Re: How to disable button in action
.. you can't do that to output PHP. Writing PHP in plain text without telling the server to parse your code (using <?php/?> tags) won't do anything. You also have the order of your file incorrect.. the "<html>" and "<head>" tags should be at the start of the page, before any other previous output, and your form should be AFTER the JavaScript function you're using is defined. And, there's no reason for you to echo all of that form stuff using PHP if you're not doing anything with PHP in it. Furthermore, you didn't define $person so it won't output anything until you do so. You also deleted parts of the script you used that were needed for it to even run correctly... if you don't know the language you're working with and don't know what something does, you shouldn't just be removing it, unless it's to reverse engineer it.
PHP Code:
<html>
<head>
<SCRIPT LANGUAGE="JavaScript">
function disableForm(theform) {
if (document.all || document.getElementById) {
for (i = 0; i < theform.length; i++) {
var tempobj = theform.elements[i];
if (tempobj.type.toLowerCase() == "submit" || tempobj.type.toLowerCase() == "reset") tempobj.disabled = true;
}
return true;
} else {
return false;
}
}
</script>
</head>
<body>
<form onSubmit="return disableForm(this);">
Name: <input type=text name=person>
<input type=submit><input type=reset>
</form>
</body>
</html>
-
Oct 8th, 2006, 12:03 PM
#17
Thread Starter
Addicted Member
Re: How to disable button in action
I want to do it by using PHP.
I want to disable the submit button after I'd clicked on it by using PHP.
-
Oct 8th, 2006, 02:55 PM
#18
Re: How to disable button in action
.. you can't do that with PHP. PHP is a server-side language, if you want something to change in PHP you must refresh the page, because the script is parsed at the server and sent to you. JavaScript is client-side, meaning that it is parsed by the browser when you're viewing it, allowing for dynamic things like the updating the time, or disabling a submit button like you want. what you want to use is JavaScript, not PHP, and there's no way you're going to get what you want without using it.. and the script I linked to you is exactly what you need. I even rearranged it all to basically do exactly what you want to do. what's your problem with it?
You can still save it as .php (although, if you have no actual PHP code in it, that will be a little pointless), but it will not be doing anything dynamic until you put code in it to do so..
-
Oct 9th, 2006, 01:23 AM
#19
Thread Starter
Addicted Member
Re: How to disable button in action
I want to use JS in a PHP page.
-
Oct 9th, 2006, 02:20 AM
#20
Re: How to disable button in action
so.. save it as a PHP file instead of an HTML file.. Javascript will work in any kind of HTML, whether it is contained in a PHP file or an HTML file.
-
Oct 14th, 2006, 12:17 AM
#21
Thread Starter
Addicted Member
Re: How to disable button in action
I couldn't do it, it isn't working.
Can you do it and attach it as a file in this topic for me pleeeeeeeeeease?
I'll be appreciated.
Thanks
-
Oct 14th, 2006, 02:24 AM
#22
Re: How to disable button in action
Why would I attach it as a file when I already posted the code you can use? I edited it for you to work the way you wanted it to.
If you do not have JavaScript enabled, it will not work. Other than that, I don't know why it isn't working for you, but it's fine for me.
-
Oct 14th, 2006, 03:17 AM
#23
New Member
Re: How to disable button in action
Why don't you use php to disable your button ? I assume that u want your user to submit only once, then after that they can't click on the go button anymore, then you can do it without using js.
PHP Code:
<?php
$flag = ""; // A flag to decide whether to disable the button or not
if (isset($_POST)) {
// Something was posted. Disable the button
$flag = "disabled";
} else {
// Nothing was posted. Enable the button
$flag = "";
}
?>
<input type="submit" value="Go" <?php echo $flag; ?>>
Hope this helps...
-
Oct 14th, 2006, 03:46 AM
#24
Re: How to disable button in action
Because that's not the point. He wants to prevent double submit, which happens when the server takes a bit to respond and the user clicks the submit button again, on the same page.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Oct 14th, 2006, 09:19 AM
#25
Thread Starter
Addicted Member
Re: How to disable button in action
I want to echo the value "$person", how?
-
Oct 14th, 2006, 06:20 PM
#26
Re: How to disable button in action
using javascript?
PHP Code:
<script language="javascript">
document.write("<?php echo $person; ?>");
</script>
-
Oct 14th, 2006, 07:46 PM
#27
Thread Starter
Addicted Member
Re: How to disable button in action
I want to echo it when I click on the submit button and I want the submit button to be disabled.
-
Oct 14th, 2006, 07:47 PM
#28
Re: How to disable button in action
 Originally Posted by kows
using javascript?
PHP Code:
<script language="javascript">
document.write("<?php echo $person; ?>");
</script>
You use PHP to generate JavaScript code that writes something during page creation?
Why not just write it directly from PHP?
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Oct 14th, 2006, 08:12 PM
#29
Re: How to disable button in action
I have no clue, I figured he might want to do something else with it besides just output it to the browser.
if you want to disable it and then echo that variable, just use the code I provided already in conjunction with the onClick attribute of the submit button.
PHP Code:
<input type="submit" onClick="return disableForm(this); document.write('<?php echo $person; ?>');" value="submit">
-
Oct 14th, 2006, 08:36 PM
#30
Re: How to disable button in action
No, you can't use document.write() after the page has finished loading. You need a different way of DOM manipulation.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Oct 14th, 2006, 08:47 PM
#31
Re: How to disable button in action
errgh, I forgot. you would just need to have a tag that was invisible on start (using CSS), and then make it visible with the onClick event. I haven't done anything in JavaScript for a long time, though, so I probably can't help you much. your best bet would probably be to go to the JavaScript forum. you can't do real-time stuff like that with just PHP.
-
Oct 15th, 2006, 07:26 PM
#32
Thread Starter
Addicted Member
Re: How to disable button in action
I want exacty when I click on submit button, it disables and begins to download file by using:
header ("Location: http://www.mywebsite/file.zip")
-
Oct 15th, 2006, 08:39 PM
#33
Re: How to disable button in action
you have to make the page submit to another script to be able to send it a new header..
-
Oct 15th, 2006, 09:44 PM
#34
Thread Starter
Addicted Member
Re: How to disable button in action
how?
Sorry, but I have no idea about JS.
Last edited by onh1986; Oct 16th, 2006 at 04:38 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|