?
Solved

How to get check box value the user selected at same asp page?

Posted on 2003-11-11
7
Medium Priority
?
1,426 Views
Last Modified: 2012-06-21
I am writing one asp page. In this page there is one check box and when clinking the Submit button, depending on the check box value, will go to two different links. My question is how do i get check box value at same page to go to one of link?
0
Comment
Question by:zhao790
[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
7 Comments
 
LVL 4

Expert Comment

by:kblack15217
ID: 9724346
Use the onclick function of the checkbox.    If you dont want this happening as soon as the user clicks the checkbox, use another event, like onclick on the submit button.   You ll have to get the reference to the checkbox using

document.getElementsbyName('chk1')[0]

<script>

function chk1_onClick(obj)
{
    if(this.checked)
    {
          location.href='page1.asp';
    }
    else
    {
          location.href = 'page2.asp';
    }
}

end function
</script>

<input type=checkbox name='chk1' onclick='chk1_onClick(this);'>
0
 
LVL 3

Expert Comment

by:barryfandango
ID: 9724376
You would use javascript to pull this one off.  Something like this:

<form name=myForm method=post target="Page1.asp">
<input type=checkbox name=chkChangeTarget onClick="ChangeTarget();">
...
</form>
<script language=javascript>
function ChangeTarget()
{
    if(myForm.chkChangeTarget.checked)
        myForm.Target = "Page2.asp";
    else
        myForm.Target = "Page1.asp";
    return;
}
</script>
0
 

Author Comment

by:zhao790
ID: 9724438
Thank for your response.

My asp code written by VB script. Can the VB script get same information or implement same functionality?
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 3

Expert Comment

by:barryfandango
ID: 9724614
zhao,

This is client-side code that will run on the user's computer.  It is not actually ASP.  If you like I could post the same code using server-side VBScript but note that this will do exactly the same thing, only it won't work in non-microsoft browsers.
0
 
LVL 3

Expert Comment

by:barryfandango
ID: 9724620
(sorry, i meant "client side vbscript" not "server-side vbscript" in the above post.)
0
 
LVL 4

Accepted Solution

by:
kblack15217 earned 150 total points
ID: 9724634
You can use VBScript clientside to pull off what you want to do, but you will limit yourself to IE broswers.   You cannot use server side code without going first to the server.

The vbscript is roughly the same

<script language="VBScript">

Function chk1_onClick(obj)
     
   if obj.checked then
         location.href = 'page1.asp';
   else
          location.href = 'page1.asp';
   end if
End Function
</script>

If you do not want to do this on the client, you can do it on the server using

if request("chk1") <> "" then
    Response.redirect "Page1.asp"
else
    Response.Redirect "Page2.asp"
end if


0
 
LVL 5

Expert Comment

by:waelothman
ID: 9726191
<script language=javascript>
function ChangeTarget()
{
    if(myForm.mycheck.checked)
        myForm.action= "Page2.asp";
    else
        myForm.actiont = "Page1.asp";
 myForm.submit()
}
</script>
0

Featured Post

Enroll in October's Free Course of the Month

Do you work with and analyze data? Enroll in October's Course of the Month for 7+ hours of SQL training, allowing you to quickly and efficiently store or retrieve data. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
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…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

650 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