Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to load different pages depending on check box value?

Status
Not open for further replies.

Apollo6

Technical User
Jan 27, 2000
418
0
0
US
I have a page that contains a dropdown listing months. When the user selects a month and clicks "Submit", I list off links to reports that match the month selected, on a new page. This all works fine.

I need to add a check box on the page the user selects the month from and if the box is checked, then load a different page, else, load the original page.

Thanks for any help!
 
<script>
function newPage() {
if (document.form.checkbox.checked){
document.href = newpage.html;
}
}
</script>

<input type=&quot;submit&quot; onClick=&quot;newPage();&quot;>

Something to that affect to see if the check box is checked then redirect via javascript. Sorry my JS skills are rough. But that should put you in the right direction.

DeZiner
Never be afraid to try something new.
Remember that amateurs built the Ark.
Professionals built the Titanic
 
DeZiner:

That works, thanks for the tip. I was thinking that it maybe better to have a set of option buttons, four to be exact.

All
Accounts Receivable
Management
Productivity

The page would only allow the user to select one of the buttons. Then depending on the month selected from the dropdown box and the option button selected, load a page that is built with both the criteria.

I have done this in MS Access/VB. Just don't know how to do the option buttons in HTML.

Any suggestions or am I better off just going my original direction?

Thanks again.
 
Option buttons are called &quot;radio buttons&quot; in html. You can do something like
[tt]
<input type=&quot;radio&quot; name=&quot;page&quot; value=&quot;all&quot; checked=&quot;checked&quot; />All<br />
<input type=&quot;radio&quot; name=&quot;page&quot; value=&quot;accounts&quot; />Accounts<br />
<input type=&quot;radio&quot; name=&quot;page&quot; value=&quot;management&quot; />Management<br />
<input type=&quot;radio&quot; name=&quot;page&quot; value=&quot;productivity&quot; />Productivity<br />
[/tt]
You can the test the value of document.form.page . It may suit you better to make the value of each option equal the URL to go to.

-- Chris Hunt
Extra Connections Ltd
 
All the radio buttons are working good. I'm trying to figure out how to do the testing of the value, which one is selected, without success.

Here's what I'm trying to use so far:

<script>
function newPage() {
if (document.form.page.value=&quot;all&quot;){
document.href = newpage.php;
}
}
</Script>

Any help with the syntax would be greatly appreciated.
 
you might be better off naming your form, something like this:

<script>
function checkRads(){
if (document.radioForm.page == &quot;all&quot;){
document.location.href = &quot;allPage.asp&quot;
}
}
</script>

<form name=&quot;radioForm&quot;>
<input type=&quot;radio&quot; name=&quot;page&quot; value=&quot;all&quot; checked=&quot;checked&quot; />All<br />
<input type=&quot;radio&quot; name=&quot;page&quot; value=&quot;accounts&quot; />Accounts<br />
<input type=&quot;radio&quot; name=&quot;page&quot; value=&quot;management&quot; />Management<br />
<input type=&quot;radio&quot; name=&quot;page&quot; value=&quot;productivity&quot; />Productivity<br />
<input type=&quot;button&quot; onclick=&quot;checkRads()&quot; />
</form>

notice in the javascript: document.LOCATION.href, and double equal signs (==) for compaison (single to set something)

 
sorry, correction:

if (document.radioForm.page.value == &quot;all&quot;){
document.location.href = &quot;allPage.asp&quot;
}
}
 
Hmmm...

This is what I am trying:

<script>
function newPage() {
if (document.Main.page_opt[0].checked){
document.location.href = rpt_name.php;
}
}
</script>

I did have an alert in the function and it works so I know the function is being called correctly. But it will still not open the rpt_name.php. I have tried putting quotes around it as well, same thing, just doesn't open the page.

Stumped at the moment...
 
quotes ;)

<script>
function newPage() {
if (document.Main.page_opt[0].checked){
document.location.href = 'rpt_name.php';
}
}
</script>
 
Still no luck!!! Grrr...

On the current page I have the following snippets:

<form name=&quot;Main&quot; onsubmit=&quot;return newPage()&quot; action=&quot;rpt_name.php&quot; method=&quot;post&quot;>

<script>
function newPage(){
if (document.Main.page_opt[1].checked){
alert(&quot;AR Option selected&quot;);
document.location.href = 'rpt_name.php';
}
if (document.Main.page_opt[2].checked){
alert(&quot;Management Option selected.&quot;);
}
if (document.Main.page_opt[3].checked){
alert(&quot;Productivity Option selected.&quot;);
}
}
</script>


My original script flowed like this:
1. User selects month from dropdown.
2. User clicks submit and rpt_name.php(page) is pulled up list several report links (pulled from database).

I've added option buttons and now the user still selects a month but also selects from four radio buttons. If the user selects any radio button besides &quot;All&quot;, I want a different page to show up and not the rpt_name.php(page).

Is it because on my current script that I have action=&quot;rpt_name.php&quot; causing me to not be able to make it load a different page in the newPage() function?

Also, I am running on a Linux box/running Apache so I am fairly sure that any ASP syntax is not going to work.?.?.?

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top