Erikal
asked on
javascript, disable form input and php
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("t heForm");
for( var i=0; i < f.elements.length; ++i)
{
f.elements[i].disabled=tru e;
}
//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.
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("t
for( var i=0; i < f.elements.length; ++i)
{
f.elements[i].disabled=tru
}
//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.
ASKER
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?
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?
>>Is there a way to exclude the form submit button
Yes:
Yes:
...for( var i=0; i < f.elements.length; ++i)
{ if( String(f.elements[i].type).toLowerCase() != "submit" )
f.elements[i].disabled=true;
}
...
ASKER
I tried it, but disabling feature stop working for all the form input fields as well and not only the submit button.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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'.
ASKER
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.
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.
>> does the submit button name has a bearing on this
No.
No.
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 !
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 !
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.