Welcome to WebmasterWorld Guest from 174.129.127.214

Forum Moderators: open

Message Too Old, No Replies

javascript form submitting

   
12:04 pm on May 14, 2003 (gmt 0)

10+ Year Member



hi all,

im having some problems with a image submit button and trying to stop it being double clicked..
atm i have this, which can stop the second click , but then doesnt continue from the first one..
any ideas..
i have had a look about but cant seem to find anything


function cont(){
if (document.forms[0].done.value == ''){
document.forms[0].done.value = true;
document.forms[0].action = '2.html';
document.forms[0].submit();
return true;
}else{
return false;
}
}


<form name=form1 onsubmit='javascript:return cont();' method=post>

am i way off track

cheer all

nat

12:49 pm on May 14, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi Nat

Lets say:

<form name="form1" onsubmit='javascript:return cont();' method=post action="2.html">
<input type="submit" id="my_button" name="action" value="Submit">
</form>

How about:

document.form1.elements['my_button'].disabled = true;

Shawn

12:57 pm on May 14, 2003 (gmt 0)

10+ Year Member



i was under the impression that you could not turn off image buttons..?!?!?

had sort of decided to change the submit image button to a hyperlink, and handle all the form actions etc in the javascript. and then turning of the hyperlink after the first time round..

unless someone can think of anything better?

cheers

nat

1:20 pm on May 14, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Sorry, I missed taht in your first post. In that case:
<form name="form1" onsubmit='javascript:return cont();' method=post action="2.html">
<input type="image" src="url..." id="my_button" name="action" value="Submit">
</form>

How about:

document.getElementById('my_button').disabled = true;

(Won't work in older browsers, but will in latest of at least IE, NN, Opera). You may be able to tweak it to get it to work across browser...

Shawn

1:25 pm on May 14, 2003 (gmt 0)

10+ Year Member



ill give that a try, cheers matey.
i wasnt aware that you could turn of image submits like i says..
but for the older browwsers i tried..

function cont(){
if (document.forms[0].done.value == ''){
var anchors = document.anchors;
for (var i=0;i<anchors.length;i++){
anchor = anchors[i];
if(anchor.name == 'submit'){
anchor.href="";
break;
}
}
document.forms[0].done.value = true;
document.forms[0].action = '2.html';
document.forms[0].submit();
}
}

btw done is a hidden field.
sadly when the link is clicked the second time, it now jumps to the top of the page, with a # after the url.. darn. like a named anchor.

2:59 pm on May 14, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I hope I am reading your post (#5) correctly... My thoughts are you can do pretty much the same thing by:

function cont(){
if (document.forms[0].done = ''){
return false;
} else {
document.forms[0].done.value = 'true';
return true;
}
}

with

<form name="form1" onsubmit='javascript:return cont();' method=post action="2.html">

Yes? Or am I missing something?

Shawn