21281 Posts in 5729 Topics by 2600 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 1174 Views |
-
(solved) JavaScript and SilverStripe

23 December 2010 at 9:04am Last edited: 23 December 2010 9:05am
Hello,
I think I have a quite easy question but i don't know how I can implement this simple example in silverstripe.
This is the HTML code:
What is the question?
<form name="Question1">
<input name="rbQuestion1" type="radio">A) possible answer 1
<input name="rbQuestion1" type="radio">B) possible answer 2
<input name="rbQuestion1" type="radio">C) possible answer 3
<input value="answer" onclick="checkQuestion" type="submit">
</form>And I want to check in the function "checkQuestion" if the choosed answer is the right answer.
function checkQuestion()
{
var QuestionChecked = false;for (var i=0; i<window.document.Question1.length; i++)
{
if (window.document.Question1.checked)
{
QuestionChecked = true;
}
}
if (QuestionChecked )
{
if(window.document.Question1.elements[1].checked==true)
{
alert("right!");
}
else
{
alert("wrong!");
}
}
else
{
alert("Please choose an existing answer!");
}
}
How I can realize this in silverstripe?Regards Beppo
-
Re: (solved) JavaScript and SilverStripe

23 December 2010 at 9:45am
1) You can create a form (see http://doc.silverstripe.org/recipes:forms or http://doc.silverstripe.org/tutorial:3-forms) and a form validation. Might feel like huge overhead if you're new to SS, but very helpful when forms get bigger.
2) If the answer is not submitted to the server, it is sufficient to include your javascript in the init() function in your page controller. (see http://doc.silverstripe.org/requirements)
-
Re: (solved) JavaScript and SilverStripe

25 December 2010 at 1:06am Last edited: 25 December 2010 1:07am
Hey dompie,
thank you very much for your answer. I tried to solve my problem with the suggestion number 2. Up to now I included the following code in the init-method of my Page.php:
Requirements::javascript("mysite/javascript/checkQuestion.js");
But now I don't know how I can implement the HTML-Code, because if I try to include the posted code in the SilverStripe editor, the editor delets a few things like the submit button and so on. Or do I also need your posted number 1 to realize what I want?
Best Regards, Beppo
-
Re: (solved) JavaScript and SilverStripe

5 January 2011 at 10:51am
Hello,
can anybody help me with my problem? I know I am a beginner but I would be very thankful if anybody can give me a few tipps.
Regards Beppo
-
Re: (solved) JavaScript and SilverStripe

11 January 2011 at 5:26am
You might want to read the Documentation first. After this some things should become clear.
-
Re: (solved) JavaScript and SilverStripe

21 March 2011 at 12:24am
I solved this problem with creating a new page type and in this page type I direct implemented the JavaScript code.
Best regards, Beppo
| 1174 Views | ||
|
Page:
1
|
Go to Top |


