0
<html>
<head>
<title>Quiz Application</title>
<script type="text/javascript" charset="utf-8" src="cordova-1.9.0.js"></script>
<script type="text/javascript" charset="utf-8">
function ready()
{
if(document.getElementById("rb2").checked)
{
alert("correct");
}else if(document.getElementById("rb1").checked)
{
alert("incorrect");
}
else
{
alert("incorrect");
}
}    
function nextPage()
 {
                 window.location = "next.html";
 }
</script>
</head>
<body>
<form method="post">
<center><h1>Quiz Application</h1></center><br><br>
<center>What does JVM stands for ?<br><br>
<radiogroup>
<input type="radio"  id="rb1"/>Java Vendor Machine<br>
<input type="radio"  id="rb2"/>Java Virtual Machine<br>
<input type="radio"  id="rb3"/>Java Viral Machine<br>
<input type="submit" id="sub" value="Freeze" onclick="ready();"/><br>
<input type="submit" id="next" value="Next Question" onclick="nextPage();"/></center>
</radiogroup>
</form>
</body>
</html>

Above is my code for redirecting my page to next page after click event.
But it is not redirecting to next page.I went through many questions on stackoverflow as well but didnt succeed.
Please help me .
Thanks in advance.

himmatwala
  • 19
  • 1
  • 8
  • There are several place you can have an error. Are you checking for `deviceready` event? What does your `config.xml` look like? Can you post that as well? –  Oct 26 '15 at 03:24
  • start by updating your cordova version, 1.9.0 is very old and won't be accepted on app store or play store – jcesarmobile Oct 26 '15 at 08:53
  • There are a plenty of questions like yours. For example, [like this](http://stackoverflow.com/questions/10435267/android-phonegap-onclick-not-working). The basic advice: try to get rid of inline javascript code and relocate all your handlers to `deviceready` event handler. – BorisR Oct 26 '15 at 16:32
  • its not working @rubanbs sir . I went through that link as well but still in vain :( – himmatwala Oct 27 '15 at 07:31

2 Answers2

0

What are you doing there? If you're doing it with jQuery mobile an example would look like this:

<html>
<head>
    <meta charset="utf-8">
    <link rel="stylesheet" type="text/css" href="css/stylesheet.css">
    <script type="text/javascript" src="js/jquery-2.1.4.min.js"></script>
    <script type="text/javascript" src="js/jquery.mobile-1.4.5.min.js">    </script>
</head>
<body>
    <div data-role="page" id="page1">
        <p>This is page 1. If you want to go to Page 2 click <a href="#page2"> here</a>.
    </div>

    <div data-role="page" id="page2">
        <p>This is page 2. If you want to go back to Page 1 click <a href="#" data-rel="back" data-transition="reverse"> here</a>.
    </div>
</body>
</html>

Changing a page by function could look like this:

function changePage() {
    $.mobile.changePage( "#loginPAGE", { transition: "none", changeHash: true });
}

Here's a pen: http://codepen.io/anon/pen/gaeoQE


Frameworks - Mobile App Development

So like i said in my comment, i would recommend you to use a framework. Since i don't know, how conversant you're in JavaScript and anything else i think you should start with jQuery. For mobile App development it's not one of the best frameworks in my opinion but it's easy to learn and thats important for you to start.

So jQuery is a thing for your website. For your mobile application you need jQuery mobile.

You go to that websites and download both. When your download is finished, you're going to open up your index.html and add the scripts to your <head></head> section so that it looks like the following:

<link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css" />
<script src="http://code.jquery.com/jquery-2.1.4.min.js"></script>
<script src="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>

These things are important. Also the order in which you include the scripts is important.

After adding this to your header, you're able to access a whole bunch of functions. All of the features are testable inside a demo environment which can be found over here: jQuery mobile Demos (1.4.5).

When you have finished that, you're going to copy my code from my pen into your <body></body> and it should work. For changing a page via javascript you can use the function changePage() which i've already posted before.

I hope this will help you, if not please let me know where exactly i can help you.

Sithys
  • 3,655
  • 8
  • 32
  • 67
  • what makes you think that he is using jquery mobile? – jcesarmobile Oct 26 '15 at 08:52
  • nothing but he has to use a framework when he's new to this. Why should he use jQuery without it? – Sithys Oct 26 '15 at 10:21
  • i need in javascript . there must be some method of doing it which i found but its not working . i dont know jquery @Sithys sir. thanks for your awesome explanation but i dont know jquery :( – himmatwala Oct 27 '15 at 07:27
  • Okay i'll edit my answer and make it more detailed. But i would recommend you to read more about the whole thing. Frameworks are a part of the whole thing also you don't need them. So give me just 5 - 10 minutes and i'm going to post a bit more to it. – Sithys Oct 27 '15 at 07:30
  • 1
    okay but javascript will help me alot .will try hands on jquery later on sir :) Anyways Thanks a lot sir – himmatwala Oct 27 '15 at 07:38
  • finished my edit. Please let me know if there are still any questions. – Sithys Oct 27 '15 at 07:45
  • what is that #loginpage stands for in changePage function ? whther it is the page on which i want to redirect ?? and i am trying your way using jquery – himmatwala Oct 27 '15 at 09:01
  • And the code which you provided is for link . i want it on button click so what should be done ? – himmatwala Oct 27 '15 at 09:41
  • This is page 1. If you want to go to Page 2 click here.

    i wrote this code on one page and next div tag on another page and i am calling via id but still its not working
    – himmatwala Oct 27 '15 at 09:52
  • You did not understand what i tried to tell you. You have to understand the whole thing behind this. Google: - Single Page Application jquery mobile - Cordova - Jquery Mobile Tutorial - Cordova Tutorial I provided a fiddle, a very detailed answer and many tipps etc. the rest is on your own. Sorry – Sithys Oct 27 '15 at 10:09
  • how to redirect to previous page in javascript do you know that sir? – himmatwala Oct 27 '15 at 11:22
0

I found out the solution for my query . i just wrote the following function onClick of a button (input type should be button and not submit then only it will work)

function nextPage()
{

document.location="nextpage.html"; //instead of window.location

}

himmatwala
  • 19
  • 1
  • 8
  • the normal way is not to route through `.html` files so roughly. You're using a framework for that. jQuery mobile, like i already said, is one of them. Single Page Applications are possible with that. – Sithys Oct 27 '15 at 12:44
  • yes i am trying with that as well @Sithys sir . I have started learning jquery ..will take some time but will do it :) – himmatwala Oct 27 '15 at 13:01
  • Great to hear, jquery and jquery mobile is a framework which is easy to learn i think. – Sithys Oct 27 '15 at 15:18