Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Forms Problems!!

Posted on 2002-04-27
13
Medium Priority
?
226 Views
Last Modified: 2010-04-01
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.
0
Comment
Question by:lina2401
[X]
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
  • 4
  • 4
  • 3
  • +2
13 Comments
 
LVL 33

Expert Comment

by:hongjun
ID: 6973233
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
0
 

Author Comment

by:lina2401
ID: 6973825
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.

0
 
LVL 12

Accepted Solution

by:
ahosang earned 100 total points
ID: 6974274
I don't know why you say JSP. This is nothing to do with JSP. JSP is a Java server-side technology
Try this:
<html>
<head>
<title></title>
<script>
function check(s) {
  if (s=="Preview") {
    document.forms[0].act.value="S1";
    document.forms[0].submit();
  } else if (s=="Finish") {
    if (confirm("Are you sure you want to end this test?")) {
      document.forms[0].act.value="S2";
      document.forms[0].submit();
    }
  }
}
</script>

</head>

<body>
Test Page
<form>
<input type="text" name="t1"><br><br>
<input type="button" name="b" value="S1" onclick="check('Preview')"><br>
<input type="button" name="b1" value="S2" onclick="check('Finish')">
<input type="hidden" name="act" value="">
</form>

</body>
</html>
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 33

Expert Comment

by:hongjun
ID: 6974349
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
0
 

Author Comment

by:lina2401
ID: 6974807
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
0
 

Author Comment

by:lina2401
ID: 6976371
This question was posted in the wrong place...so I moved it to the javascript section..
0
 
LVL 12

Expert Comment

by:ahosang
ID: 6976528
Did you try my suggestion?
0
 

Author Comment

by:lina2401
ID: 6977006
yep and I got the same error msg!!
0
 
LVL 12

Expert Comment

by:ahosang
ID: 6979298
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).
0
 
LVL 33

Expert Comment

by:hongjun
ID: 6989531
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
0
 

Expert Comment

by:sushifish
ID: 7000549
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.

0
 
LVL 33

Expert Comment

by:hongjun
ID: 7002840
Why a delete!!!

hongjun
0
 
LVL 5

Expert Comment

by:Netminder
ID: 7034424
Force-accepted by
Netminder
CS Moderator

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

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Explore the ways to Unlock VBA Project Password Excel 2010 & 2013 documents. Go through the article and perform the steps carefully to remove VBA Excel .xls file.
Tech spooks aren't just for those who are tech savvy, it also happens to those of us running a business. Check out the top tech spooks for business owners.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

636 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