473,503 Members | 1,641 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Using Onchange or Onclick

106 New Member
I have a form which contains a combo box and a table ..i need that whenever the user selects an option from the combo box the page is reloaded but with the table data related to that client he choosed from the box .. i really need help with this and im very confused whether to use <select onchange= > or <option onclick>
and also how to tell him to reload same page
Nov 9 '08 #1
13 8371
Markus
6,050 Recognized Expert Expert
--Moved to Javascript.
Nov 9 '08 #2
gits
5,390 Recognized Expert Moderator Expert
typically you use the onchange-event of the select-node. and for a submit you may call a function that uses the submit()-method
Nov 9 '08 #3
bnashenas1984
258 Contributor
Here's what you can do:

Expand|Select|Wrap|Line Numbers
  1. <select onchange="this.form.submit()">
  2.  
Don't forget to put your combo box in a form.
Each time the user changes the value of your combo box the form gets submited

Hope it helps
Nov 9 '08 #4
jessy
106 New Member
Okay now i managed to make the data changes with the user's selection BUT i faced another huge problem which is
the user is presented with many options(clients) which are generated in a while loop and an option which is not in the while loop which states ALL clients
when the page loads for the first time the data in the table are for all clients but once i select any option and then try to select ALL clients again Nothing appears so i was asking if their anyway i could handle this
here's the code:
Expand|Select|Wrap|Line Numbers
  1. <select onChange=this.form.submit(); name="clients"> 
  2. <option >All Clients </option>
  3. <?$query=mysql_query("select * from clients");
  4.     while($row=mysql_fetch_array($query))
  5.     {   
  6.  
  7.    echo"<option value=$row[c_id] >$row[c_name]</option>";    
  8.  
  9.     }
  10. $sql="select sum(order_price) from orders";
  11.  
  12.      if($_POST[clients])
  13.         { 
  14.             $clients=$_POST[clients];
  15.  
  16.         $sql="select sum(order_price) from orders where client_id=$clients";
  17.          }
  18.  
  19.           $query=mysql_query($sql);
  20.  
  21.                $row=mysql_fetch_array($query);
Nov 10 '08 #5
bnashenas1984
258 Contributor
That's because you don't have a VALUE attribute for your first option which is ALL CLIENTS

When your page loads for the first time , the code recieves no value from your combo box but when you choose ALL CLIENTS for the second time then your PHP code recieves ALL CLIENT.

What you need to do is to set a NULL value for your first option like this

Expand|Select|Wrap|Line Numbers
  1. <option value="">All clients</option>
  2.  
Post back if there is any other problem
Nov 10 '08 #6
jessy
106 New Member
Okay i made what u say But still facing the same problem nothing happens when i press ALL CLIENTS :(
Nov 10 '08 #7
acoder
16,027 Recognized Expert Moderator MVP
Your onchange submits the form. Check that your PHP code displays all clients when the value of clients is empty.
Nov 10 '08 #8
jessy
106 New Member
Yeah thats exactly what i need to do !!
display all clients when value is empty ? all clients are displayed only once when the page loads for the very first time but then nothing appears again
Nov 10 '08 #9
acoder
16,027 Recognized Expert Moderator MVP
Your PHP code needs a bit of alteration too. On line 11, you have:
Expand|Select|Wrap|Line Numbers
  1. if($_POST[clients])
you need to add a condition for when the POST value is empty.

Note that you can also avoid a page reload using JavaScript/Ajax.
Nov 10 '08 #10
jessy
106 New Member
Okay, now i added a condition but nothing changes

Any help on how to use AJax for this or any tutorial ...!
Nov 10 '08 #11
acoder
16,027 Recognized Expert Moderator MVP
What condition did you add?

Ajax is useful if you want to avoid the page reload. If that's not a requirement, then it's not necessary. If you want a tutorial, check out the links in the Off-site Links thread.
Nov 10 '08 #12
jessy
106 New Member
:( i added the Condition

Expand|Select|Wrap|Line Numbers
  1.  if($_POST[clients]&&!empty($_POST[clients]))
also i checked some ajax tutorial but felt very depressed things r not that easy i thought
Nov 10 '08 #13
acoder
16,027 Recognized Expert Moderator MVP
Shouldn't $_POST[clients] be $_POST['clients']? If you have more problems with the PHP code, start a new thread in the PHP forum.
Nov 10 '08 #14

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

Similar topics

2
42840
by: kie | last post by:
hello, when i create elements and want to assign events to them, i have realised that if the function assigned to that element has no parameters, then the parent node values can be attained. ...
4
11923
by: rick | last post by:
The following basic script works fine in firefox by not in IE. Can anyone spot the problem? In IE I can only delete the first line but not the lines created by javascript. Also, look at the HTML...
2
7018
by: Andy Goldstein | last post by:
I have a table where all the TRs have an onClick handler registered. One (and only one) of the rows has 2 text input boxes, where each textbox has an onChange handler registered. Both the onClick...
4
6096
by: Bart van Deenen | last post by:
Hi all I have a script where I dynamically create multiple inputs and selects from a script. The inputs and selects must have an associated onchange handler. I have the script working fine on...
7
8246
by: Bruno Alexandre | last post by:
Hi Guys, I'm having a HUGE problem with Javascript under IE, the code below belongs to a page http://filterqueen.brinkster.net/test.aspx it works fine under Firefox, but not in IE... does...
2
1924
by: saurabh | last post by:
Hi in my code i have a line Rad2.Attributes.Add("onclick","onchange2();"); This is working perfectly fine.When user clicks the Rad2 radiobutton onchange2(); function gets executed. but in...
1
24727
by: s.chelliah | last post by:
Hi, I am trying to use javascript, div tag and radio button to disable/enable a text box. It works fine in netscape and firefox, but in IE, the text box is not disabled when the user checks the...
2
3124
by: shivendravikramsingh | last post by:
hi friends, i m using a ajax function for retrieving some values from a database table,and display the values in required field,my prob is that the ajax function i m using is working f9 once,but if...
14
9188
by: The Natural Philosopher | last post by:
This is a nasty one and I can't see my way out of it. I have a bunch of select statements in a form, and each select statement has an onchange="do_something(this)" in it, and this works...
5
4436
by: thatcollegeguy | last post by:
Below are my 3php and 2js files. I create a table using ajax/php and then want to change the values in the tables add(+ number for teamid) id's for each specific td in the table. I don't know...
0
7194
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7070
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
7267
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
7316
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
5566
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
3160
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1495
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
729
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
372
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.