Link to home
Start Free TrialLog in
Avatar of lina2401
lina2401

asked on

Forms Problems!!

I don't know if this is the right place to post this or not!!
anyway here is the situation..
I have a form with 2 submit buttons (Preview & Finished)..the form should display a number of questions (for students to answer) that are obtained from the database(I used PHP and Mysql) and for that it contains a lot of input types(radio,checkbox,text)..
Preview is for previewing answers.
Finished is for storing results and here I used javascript to display a confirmation message to see if  he/she really wants to end the test if he/she clicked on OK his/her answers should be stored.. but non of the values is recognized at that part of code!!I tried to do this without the confirmation message and it worked!!
I don't know if this is a javascript problem or not?? and if so how can I fix it??

Thanks.
Avatar of hongjun
hongjun
Flag of Singapore image

How you go about doing the confirmation? Below is just an example.

<script language="Javascript">
<!--
function FinishClick()
{
        // ok pressed
     if ( confirm("Are you sure you want to submit?") )
          document.frmMain.submit();
}
//-->
</script>

<form name="frmMain" action="second_page.jsp" method="post">
...
<input type="button" value="Finish" onclick="FinishClick();">
</form>


hongjun
Avatar of lina2401
lina2401

ASKER

this is what I did.
<script language="Javascript">
<!--
function ConfirmChoice2()
{
answer = confirm("Are you sure you want to end this test?")
if (answer==1)
{
location = "student_test.php?action=Finished"
}
}
//-->
</script>
<form action="student_test.php" method="post">
...
<input type="submit" name="action" value="Preview">
<input type="submit" name="action" value="Finished" onclick=" ConfirmChoice2(); return false;">
</form>

student_test.php
if ($action==Finished)
....
elseif ($action==Preview)
....
else
....

I'm not familiar with jsp!!so any help would be appreciated.

ASKER CERTIFIED SOLUTION
Avatar of ahosang
ahosang
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Try this


<script language="JavaScript">
<!--
function PreviewPage()
{
     document.frmMain.type = "preview";
     document.frmMain.submit();
}

function ConfirmChoice2()
{
     if (confirm("Are you sure you want to end this test?"))
     {
          document.frmMain.type = "finish";
          document.frmMain.submit();
     }
}
//-->
</script>
<form name="frmMain" action="student_test.php" method="post">
...
<input type="button" value="Preview" onClick="PreviewPage();">
<input type="button" value="Finished" onClick="ConfirmChoice2();">
<input type="hidden" name="type">
</form>



A hidden field named type will be posted to student_test.php. Check the value of this value to determine is it a preview or a finish request.



hongjun
I tired that and I got an error message in these lines:
-document.frmMain.type = "preview";
-document.frmMain.type = "finish";
"Object doesn't support this property or method"
isn't because I use "get" instead of "post"??

-thanks
This question was posted in the wrong place...so I moved it to the javascript section..
Did you try my suggestion?
yep and I got the same error msg!!
Impossible to get exactly the same error message!!
My code works as a standalone page. If you incorporating it into your own page and get an error, post the code or the error message(preferably the code).
lina, I suggest you continue to work on this question instead of moving to javascript TA. This can be unfair to those experts who have put in effort on this question.

hongjun
Possible error:

don't use

location=("student_test.php?action=Finished");

but replace the above code with following code:

document.form_name.action.value="Finish";
document.form_name.submit();

and please insert this into your <form> HTML tag

<form action="student_test.php" method="post" name="form_name">

<input type="hidden" name="action">
</form>

hope this helps.

Why a delete!!!

hongjun
Force-accepted by
Netminder
CS Moderator

hongjun: points for you at https://www.experts-exchange.com/jsp/qShow.jsp?ta=jsp&qid=20304611