Solved

javascript, disable form input and php

Posted on 2008-10-07
9
1,045 Views
Last Modified: 2013-12-12
Hi,
hielo kindly suplied me with a cute little Javascript code for disabling form input after a given time.
The code works perfectly on its own when written in the html section.
Here is the code:
========================
<script type="text/javascript">
      window.onload=init;
      function init(){
            var minutes=15;
            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)
            {
                  f.elements[i].disabled=true;
            }
            //if you want to auto-submit the form, uncomment the next line
            //f.submit();
      }
</script>
=======================================

However, I need to be able run the php code on the page at form timeout. The php code, without the form  runs without a problem until I insert the above script.

With the timeout script, the form submit button is also disabled and therefore the php code does not run.

Where and How should I insert this timeout/input disable script, so that I still have the submit button of the form available, which runs the php code.
0
Comment
Question by:Erikal
  • 4
  • 4
9 Comments
 
LVL 82

Expert Comment

by:hielo
Comment Utility
>> I need to be able run the php code on the page at form timeout
The php code will run on the server BEFORE you actually send that javascript to the browser. The browser does NOT execute php. So that javascript will not interfere with php. You may have some syntax problem on your file as a whole that is preventing everything else from working as expected.
0
 

Author Comment

by:Erikal
Comment Utility
The part of the php code runs after the user clicks the submit button of the form and produces an alert box, which in turn directs the user to Maths page.
When this javascript form reaches timeout, it also freezes the submit button. I tried auto submit as you suggested, but still no progress on the rest of the php execution.

This is the assessment test you were very kind to help me with and as you remember we got it to work perfectly.
I am not sure what I am doing wrong.
Is there a way to exclude the form submit button from the freeze at timeout, so that it is still active?
0
 
LVL 82

Expert Comment

by:hielo
Comment Utility
>>Is there a way to exclude the form submit button
Yes:

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

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

                  f.elements[i].disabled=true;

            }

...

Open in new window

0
 

Author Comment

by:Erikal
Comment Utility
I tried it, but disabling feature stop working for all the form input fields as well and not only the submit button.
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 82

Accepted Solution

by:
hielo earned 500 total points
Comment Utility
>>disabling feature stop working for all the form input fields
??? The attached example works. Not sure what markup you have
<!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=(2/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;

            }

            //if you want to auto-submit the form, uncomment the next line

            //f.submit();

      }

</script>
 

</head>

<body>

<form id="theForm">

	<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
This may be a very stupid question, but does the submit button name has a bearing on this. My submit button is named is 'Submit_Eng1'.
0
 

Author Closing Comment

by:Erikal
Comment Utility
Hielo,
many thanks it is working.
I should have just copied your code instead of keying it in. I apparently, I typed the S of the String in lower case.

Great stuff.
0
 
LVL 82

Expert Comment

by:hielo
Comment Utility
>> does the submit button name has a bearing on this
No.
0
 

Expert Comment

by:kalloo
Comment Utility
Hey guys !! this form doesnt move any value !!
ex. after submitting this form .. i put this code
<?php
echo $_POST['day'];
echo $_POST['month'];
echo $_POST['year'];
?>
and i see nothing !! No result at all ! tht means the code doesnt carry any value at all
Please i need help with this !
0

Featured Post

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

Join & Write a Comment

Suggested Solutions

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

728 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

9 Experts available now in Live!

Get 1:1 Help Now