...

View Full Version : Javascript "Please Wait.." Function Question



theflyingminstr
11-24-2010, 04:36 PM
Hi, I'm having some issues turning this "Please Wait"/Disabled button into a function.


<input type="submit" value="Submit Form" onClick="this.disabled = 'true'; this.value='Please wait...';" />


function pleasewait()
{
this.disabled = 'true';
this.value='Please wait..'
}

<input type="submit" value="Submit Form" onClick="pleasewait();" />

Thanks much

Philip M
11-24-2010, 05:14 PM
<script type = "text/javascript">
function pleasewait(which) {
which.disabled = true;
which.value = 'Please wait..'
}
</script>
<input type="submit" value="Submit Form" onClick="pleasewait(this);" />


All advice is supplied packaged by intellectual weight, and not by volume. Contents may settle slightly in transit.

theflyingminstr
11-24-2010, 05:26 PM
Sweet thanks so much Philip!

Sorry if I'm getting too off the subject but I'm having a problem integrating this with my form validator. When I click the button, not matter whether the form validation is returned true or not the button says "Please wait.." and is disabled.


function validate_required(field,alerttxt)
{
with (field)
{
if (value==null||value=="")
{
alert(alerttxt);return false;
}
else
{
return true;
}
}
}

function validate_form(thisform)
{
with (thisform)
{
if (validate_required(email,"Email must be filled out!")==false)
{email.focus();return false;}
}
}

Mucho appreciated!!

Philip M
11-24-2010, 05:52 PM
Well, yes, What did you expect? Click button > run function.

You must show how the validation function is being called in you <form ...... onsubmit = "whatever()" ....> code.

You should note that form validation of the pattern if (value==null||value=="") is barely worthy of the name, and virtually useless, as even a single space, an X or a ? will return false, that is pass the validation. Numeric values, such as zip codes and phone numbers, should be validated as such. Ditto email addresses. This topic has been covered many times before in this forum.

theflyingminstr
11-24-2010, 05:56 PM
I'm sorry.....

The function is called like:


<form action="" name="form" onsubmit="return validate_form(this);">

Philip M
11-24-2010, 06:13 PM
There is no point in disabling the submit button or changing its value as submitting the form refreshes the page, restoring the original value.


<form name= "myform" onsubmit = "return validate()">
<input type="submit" name = "subButton" value="Submit Form" />
</form>

<script type = "text/javascript">
function validate () {
document.myform.subButton.disabled = true;
document.myform.subButton.value='Please wait..'
alert ("Delay to show effect of form submission")
return true;
}

</script>

theflyingminstr
11-24-2010, 06:32 PM
Would it be plausible to add this javascript call after the form has been submitted then?

Philip M
11-24-2010, 06:44 PM
Would it be plausible to add this javascript call after the form has been submitted then?

No. Of course not. Submitting the form refreshes the page and starts over - as my example has demonstrated.

In any case, what is the user supposed to wait for? Godot? :D And what will cause that wait to end?

theflyingminstr
11-24-2010, 06:51 PM
Ok, understood. Thanks so much for clearing that up!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum