473,395 Members | 1,761 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Which button was clicked - JSP with JavaScript

8
I have two JSP pages PageOne.jsp and PageTwo.jsp.
On the PageOne.jsp I have TextBoxOne and TextBoxTwo.
Next to each of these textboxes there is a "Wizard1" button and "Wizard2" button.
When the user clicks any of these "Wizard" buttons it will take him to PageTwo.jsp by popping up a new jsp window (PageTwo.jsp).
On this PageTwo.jsp the user will need to fill out a form and then click "Done" button.
After he clicks the "Done" button I need to close the PageTwo.jsp, and take the user back to the PageOne.jsp and populate one of the textboxes (depending on which Wizard Button was clicked).

One of the Wizard buttons already works and populates the TextBoxOne. Now I need to get the second Wizard botton working without creating a new JSP page and a new servlet.

I'm thinking about puting an IF stetement on to my PageTwo.jsp, which will look something like this:


if (Wizard1 was clicked)
{
Populate TextBoxOne
}

If (Wizard2 was clicked)
{
Polulate TextBoxTwo
}

Now, my question is, I want to know what is the syntax for writing this IF statement? How can I find out which button was clicked?


Thanks,
Nov 13 '07 #1
7 4310
jambyl
8
I tried doing something like this, but it is not working:

if (document.PageOneForm.button.name == 'Wizard1') {
opener.document.PageOneForm.TextBoxOne.value = "1";
close();
return true;
}

Thanks
Nov 13 '07 #2
Dasty
101 Expert 100+
Just remember the last pressed button number in global variable in the first page.

[HTML]<script language="javascript">
var number_of_button_i_clicked = null;
</script>[/HTML]

In onclick event of the buttons you'll set that variable like:

Expand|Select|Wrap|Line Numbers
  1. function click_handler_for_button_1()
  2. {
  3.   var new_window;
  4.   number_of_button_i_clicked = 1;
  5.   new_window = window.open('PageTwo.jsp', [your properties]);
  6. }
and finally your IF code in page 2 will look like:

Expand|Select|Wrap|Line Numbers
  1. if (opener.number_of_button_i_clicked == 1)
  2. {
  3.   [populate box 1]
  4. }
  5. .. etc
  6.  
or are you looking for something different?
Nov 13 '07 #3
jambyl
8
Thank you for your reply!
Could you please explain what "parent" means? What should I write in my case? How is it going to know what is the value of the "number_of_button_i_clicked" is?

if (parent.number_of_button_i_clicked == 1)
{
[populate box 1]
}
.. etc
}

BTW, I'm not using PHP. I am using JavaScript inside of a JSP page.

Thanks,
Jambyl
Nov 13 '07 #4
Dasty
101 Expert 100+
It's not "parent" it's "opener" (sorry). And those codes are javascript (not php) - again, my fault - all fixed (I am kind of retard).

number_of_button_i_clicked is global variable in PageOne, and you can read its value from PageTwo by using opener.number_of_button_i_clicked reference.
Nov 13 '07 #5
jambyl
8
Dasty,
Thank you for your help! It works like a champion!!! :))

If you don't mind, I have one more question to ask you.

I don't know how to do the following:

After I populate the TextBoxOne (using our Wizard1 button), I want the value in TextBoxTwo to automatically appear three times the value of TextBoxOne.
For example if the value that we got in TextBoxOne is 3, I want the value in TextBoxTwo to be automatically become 9.

This is not going to be the case for TextBoxTwo. That means If we populate the value in TextBoxTwo (using out Wizard2 button), we don't want anything to show in TextBoxOne.

Thank you in advance!

Jambyl
Nov 13 '07 #6
Dasty
101 Expert 100+
I dont understand, who can enter values in TextBoxOne and TextBoxTwo? Are you doing it only by your js code? Or are the users free to enter their values into those boxes?

1) If you are entering values into those boxes just from that mentioned PageTwo window, why dont you set both values in same function? like:

Expand|Select|Wrap|Line Numbers
  1. opener.document.PageOneForm.TextBoxOne.value = new_value;
  2. opener.document.PageOneForm.TextBoxTwo.value = new_value * 3;
2) if the users enter the values, you should use onchange event to count new value in second textbox like:

Expand|Select|Wrap|Line Numbers
  1. <input type=text name=TextBoxOne id=TextBoxOne onchange="count_second_box(this);">
  2.  
  3. function count_second_box(obj)
  4. {
  5.   document.PageOneForm.TextBoxTwo.value = this.value * 3;
  6. }
This code is very simplified (no format checks .. etc) just to give you an idea.
Nov 13 '07 #7
jambyl
8
This is great! Thank you!!!
I appreciate your help!!!

Kind regards,
Jambyl
Nov 13 '07 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: AFN | last post by:
I'm trying to set a submit button to change text and color when clicked. Like saying "please wait" instead of "submit" and then changing the background color and text color. All works, except for...
4
by: actionwoman63 | last post by:
Dear all I need to be able to check which one out of two submit buttons within the same form was pressed in a javascript function prior to form submission. And before I get flamed for not...
3
by: Dave | last post by:
If you have multiple buttons on a web form, how can you detect which control was clicked in the Page_Load event Thanks, Dave
2
by: Daniel Walzenbach | last post by:
Hi, I created an ASP.NET Datagrid where a single row can be selected by clicking anywhere on the row (according to...
7
by: Amadelle | last post by:
Hi all and thanks in advance, I am stuck! I can't figure out how to identify which button was clicked on my ASP.NET page in the PostBack event? So what I am trying to do is to is to have an if...
3
by: Terry Olsen | last post by:
I have a DataGrid with a Template Column. In the ItemTemplate I have an ImageButton. I want to have the user select a row by clicking on the ImageButton. When the user clicks an ImageButton,...
7
by: ujjc001 | last post by:
Hello, it a .net app, in my client javascript code I would like to find out what event caused the page to validate. No, setting a hidden this or that will not do. I just want to know what event...
6
by: John Smith | last post by:
How can I find out which control performed PostBack? I have put this code inside my Page_Load event: Response.Write(Page.Request.Params.Get("__EVENTTARGET")) but it doesn't write to response...
5
by: sumeetmakkar | last post by:
Hi all, I am a begineer and working on a project. Facing trouble linking a submit buuton to a page of my choice.Script i am using is: <SCRIPT language=JavaScript><!-- function validate(form) {...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.