Solved

php, javascript form input freeze at timeout

Posted on 2008-10-07
8
486 Views
Last Modified: 2013-12-12
Hello,
OK I running in circles here. That is me not knowing nearly enough about php ,and any other script language for that matter.
On a previous question I asked about disabling the form input fields at timeout. Which worked wonderfully, but what I did not realize is that the disabled inputs would no longer be available for the following php code to work with, unless of course I have missed something again.
The link to the previously closed question is:
http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_23793573.html

Once the form inputs are disabled and the user clicks the submit button, I need the values of the frozen input fields to be picked up by the php script and processed, so that the results are inserted into the corresponding sql table.

Would I be able to do that and how.

Many thanks
0
Comment
Question by:Erikal
  • 4
  • 4
8 Comments
 
LVL 82

Expert Comment

by:hielo
Comment Utility
My apologies, I missed that completely. Use this:

            for( var i=0; i < f.elements.length; ++i)
            {
                  if( String(f.elements[i].type).toLowerCase() != "submit" )
                     {
                           f.elements[i].style.color="#aaaaaa";
                        f.elements[i].readOnly=true;
                        }
            }
0
 

Author Comment

by:Erikal
Comment Utility
Yes it works, but yet again I need your help.
The readonly command only works on the text inputs. I have radio buttons in the form as well and radio buttons are still active.
Any suggestions?

Thank you.
0
 

Author Comment

by:Erikal
Comment Utility
Hi,
I read somewhere that may be it is possible to disable the form alements (all or just the radios), which is what I need. Then, in order to get them passes on to the php, enable them on submit.
If this is true, how would I need to modify the code (would I need another function for changing disable=true to disable=false). Then to activate that function in the <form .............. onSubmit="javascript:enablefunction()> or something like that.

Any suggestions?
0
 
LVL 82

Expert Comment

by:hielo
Comment Utility
for( var i=0; i < f.elements.length; ++i)
            {
                  if( String(f.elements[i].type).toLowerCase() != "submit" )
                     {
                           f.elements[i].style.color="#aaaaaa";
                        f.elements[i].readOnly=true;
f.elements[i].onclick=function(){return false;};
                        }
            }
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:Erikal
Comment Utility
This does not quite work I am afraid.
The onclick=function(){return false;}; just disables the radio buttons altogether. That is fine, but when you click on a radio button in a question it just clears any existing entry on that question. Hence, the record field on the sql table for that question goes blank.
What i mean is, if the user chooses one of the buttons for a given question and decides, after timeout, to edit/change that answer, any exiting answer is just cancelled on that question.
0
 
LVL 82

Accepted Solution

by:
hielo earned 500 total points
Comment Utility
How about this: diable all the elements except the submit. Once the user clicks the submit button, then re-enable all the fields so that the browser sends all the values.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"

 "http://www.w3.org/TR/html4/loose.dtd">

 

<html>

<head>

<title></title>

<script type="text/javascript">

      window.onload=init;

      function init(){

            var minutes=(5/60);

            setTimeout("nextPage()", 1000*60*minutes );

      }

      function nextPage(){

            //assuming you have <form id="theForm"...>

            var f = document.getElementById("theForm");

            for( var i=0; i < f.elements.length; ++i)

            {

		  	if( String(f.elements[i].type).toLowerCase() != "submit" )

                  f.elements[i].disabled=true;

            }

      }

	 function activate(f){

            for( var i=0; i < f.elements.length; ++i)

            {

                  f.elements[i].disabled=false;

            }

	return true;

	}

</script>

 

</head>

<body>

<form id="theForm" onsubmit="return activate(this)">

	<input type="text"/>

	<input type="text"/>

	<input type="text"/>

 

	<input type="submit" />

	

</form>

</body>

</html>

Open in new window

0
 

Author Comment

by:Erikal
Comment Utility
Yes!
Great! It worked.
many thanks
0
 
LVL 82

Expert Comment

by:hielo
Comment Utility
you are welcome
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now