Solved

php, javascript form input freeze at timeout

Posted on 2008-10-07
8
488 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
ID: 22661384
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
ID: 22662271
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
ID: 22663022
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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
LVL 82

Expert Comment

by:hielo
ID: 22663058
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
 

Author Comment

by:Erikal
ID: 22663392
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
ID: 22664146
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
ID: 22664609
Yes!
Great! It worked.
many thanks
0
 
LVL 82

Expert Comment

by:hielo
ID: 22669202
you are welcome
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

773 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