Jump to content

losing posted data with onclick="this.disabled=true"


Recommended Posts

hi there

 

this is kind of a php and javascript issue

 

so i have a form, and i want the submit button to be disabled once i click it

 

i have no problem, this can be done by adding 'onclick="this.disabled=true"' to the input

 

the problem is that if i use that javascript then the data entered in the form does not actually get posted after the submit button is clicked and disabled.

 

this form also uses AJAX so the page does not get refreshed, so using isset to disable the input is out of the question.

 

anyone have any ideas?

store your post variable in session or use hidden fields or reload the page to its self eg php self

 

the page doesnt refresh, it uses ajax so there is no page refreshing nor do i want any page refreshing (the whole reason i am using ajax in the first place)....thats the big problem here.....

 

as for the hidden fields - could you give me some type of example of how they could work when none of the form data is actually being posted due to the submit button becoming disabled?

if you use ajax then i guess you can do something like this

 

first when you click the button to submit using ajax submit the whole page or all the value of your form then bring it back using inner html like on your hidden fields and maybe you can use serialization to do this

Ironically enough, I had this same problem. So then I thought, what was my main goal in disabling the submit button? To stop people from clicking it again. So then I decided instead to "hide" it. Different method, but same standards.

 

<input type="submit" onclick="this.style.display='none';">

 

This should work :-)


<script language="javascript">
<!--
function DisableButton() {
     var sub = document.getElementById('submit');
     sub.disabled = true;
     //return true; //if you want the form to go through... which i doubt you do
     return false;
}
//-->
</script>

<form action="" onsubmit="return DisableButton();">
<input type="submit" name="submit" id="submit" value="Submit!" />
</form>

 

That will hide it without the form not submitting.

 

Hopefully you can implement that into you situation....

 

 

I also think I may have misunderstood you, but that's a soloution to the question I thought you were answering ;p.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.