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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Wan't to know wich button the user pressed.

Status
Not open for further replies.

delpierro

Technical User
Mar 12, 2007
23
NL
Please can someone help me with this.
The first frame i called 'side' and contains a little menu
The second frame is the content of the choosen menu-item.

I want to know if a user pressed the 'add record' button from the menu (side-frame) or the 'save to database' button from the content-frame

Here is the code:

index.htm (frameset)
<html>
<head>
<title>framespage</title>
</head>

<frameset rows="100%" frameborder="0" border="0" framespacing="0">
<frameset cols="175,86%">
<frame src="side.asp" name="side" id="side" title="side" scrolling="no" noresize / marginwidth="0" marginheight="0" target="_side">
<frame name="content" src="content.asp" marginwidth="0" marginheight="0" scrolling="auto" target="_self">
</frameset>
<noframes>
<body topmargin="0" leftmargin="0">
</body>
</noframes>
</frameset>
</html>



side.asp
<html>
<head>
</head>
<script type="text/javascript">
function Goto(Page)
{
parent.content.document.location.href = Page;
}
</script>
<body bgcolor="#008000">
<p><input type="button" value="Home" name="cmd_home" onclick=""></p>
<p><input type="button" value="add record" name="cmd_add" onclick="Goto('record_add.asp?new=1')"></p>
<p><input type="button" value="Login" name="cmd_login" onclick=""></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p><b><font color="#FFFFFF">this is the side frame</font></b></p>
</html>



content.asp
<html>
<head>
<title>content</title>
<base target="_self">
</head>
<body bgcolor="#800000">
<p><b><font color="#FFFFFF">this is the content frame</font></b></p>
</html>


record_add.asp
<html>
<body bgcolor="#800000">
<form method="POST">
<p><input type="text" name="txt_text1" size="20"></p>
<p><input type="submit" value="Save to database" name="cmd_save"></p>
</form>
<p><b><font color="#FFFFFF">this is the content frame</font></b></p>
</html>

 
When do you want to know this? before redirect, after redirect??

[monkey][snake] <.
 
You could set up in the onclick handler of each button to set a flag in the main page to keep track of which button is pressed. Unfortunately there is no way for javascript to track which button is checked automatically, so you have to have a variable keep track of the information. Since you're using frames, it will be a little bit more complicated (probably best idea to keep the tracking variable in the main page and use parent.variableName to access it), but this is the general idea:
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">[/URL]
<html xmlns="[URL unfurl="true"]http://www.w3.org/1999/xhtml">[/URL]
<head>
<title>title test</title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<script type="text/javascript">

var whichButton = "";

</script>
<style type="text/css"></style>
</head>
<body>

<input type="button" value="1" name="buttonNumber1" onclick="whichButton = this.name; alert(whichButton)" /><br /><br />
<input type="button" value="2" name="buttonNumber2" onclick="whichButton = this.name; alert(whichButton)" />

</body>
</html>

-kaht

Looking for a puppy? [small](Silky Terriers are hypoallergenic dogs that make great indoor pets due to their lack of shedding and small size)[/small]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top