Forum : please i am so confuse with the switch(page).That is linking it to a page.
Brief description  about Online courses   join in Online courses
View Clement  Osei Tutu 's Profile

please i am so confuse with the switch(page).That is linking it to a page.

Please do help me know how this code will work.I am not knowing what to do to make this work.please here is the code.

<html>
<head>
<title></title>
<script type="text/javascript">
page = document.frmOne.cmbAge.value
switch (page) {
case "1":
document.URL = "page1.html"
break
case "2":
document.URL = "page2.html"
break
case "3":
document.URL = "page3.html"
break
case "4":
document.URL = "page4.html"
break
default:
alert("An error occurred, so we are staying here")
}
</script></head><body>
</html>

Thanks so much.

Clement Osei.
Asked by Clement Osei Tutu | Dec 25, 2010 |  Reply now
Replies (3)
View teacher siliconindia 's Profile
Hi Clement,

i want to know your approach to problem,, how u tried and all.. because u already completed html part. because u are having so many doubts and problems with javascript it seems.
Jan 2, 2011
View clement osei-tutu 's Profile
Hi Sir,
Thanks so much.
Please i am still do not get to understand how this will work in a drop down menu or any thing of that sort.

Please with all the honor..please do explain to me better because i can skip this while i'm not understand.

Please i have this code here that i want you to see if you can add the needed or tell me what to do to make it finish it task.

please kindly continue it for me..plaese

<html>
<body>
<script type="text/javascript">
page=document.frmone.cmbAge.value
switch (page) {
case "1":
document.URL = "page1.html"
break
case "2":
document.URL = "page2.html"
break
case "3":
document.URL = "page3.html"
break
case "4":
document.URL = "page4.html"
break
default:
alert("An error occurred, so we are staying here")

}
</script>
<form name=formone>

..........
..........
...........
..........

</body>
</html>

Thank for your good work.

Clement Osei.
Dec 27, 2010
View teacher siliconindia 's Profile
Hi Clement,

<html>
<head>
<title></title>
<script type="text/javascript"> // javascript code starts here
page = document.frmOne.cmbAge.value // u are getting some form value, formname = frmone, fieldname or HTML form element name=cmbAge and you are assigning that to page variable. According to your case, page value will be in range 1-4, or it ll go to default case, where u alert error message.
switch (page) {
case "1":
document.URL = "page1.html" // if page is '1', document.URL ll be "page1.html"
break
case "2":
document.URL = "page2.html" // if page is '2', document.URL ll be "page2.html"
break
case "3":
document.URL = "page3.html" // if page is '3', document.URL ll be "page3.html"
break
case "4":
document.URL = "page4.html" // if page is '4', document.URL ll be "page4.html"
break
default:
alert("An error occurred, so we are staying here")
}
</script></head><body>
</html>

Dec 26, 2010