Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

php, javascript form input freeze at timeout

Posted on 2008-10-07
8
489 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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
This article discusses four methods for overlaying images in a container on a web page
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to count occurrences of each item in an array.

840 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