views:

47

answers:

2

Hello everyone,I have a Select tag in the form in which i am giving the Static Options, My problem is to know "how to retrieve the value which i have selected",I dont want to use any Button to submit the value which i have selected.So i want to go with the "Onchange event " of select tag.

here's the code by which am populating the select tag:

 print qq[<td>Records PerPage</td>];
 print qq[<td><select name="'records'" size="1"><option value="2">2<option value="4"
   selected>4<option value="6">6<option value="10">10</select></td></tr>];

Please do help me Find the solution. Thank You

+1  A: 

EDIT: WITH ONCHANGE

Ok to get your value from a combo box use javascript

   function getCombo1(sel) {
       var value = sel.options[sel.selectedIndex].value;  
   }
   <select id="combo1" onchange="getCombo1(this)">
   <option value="">Select combo</option>
   <option value="Value1">Text1</option>
   <option value="Value2">Text2</option>
   <option value="Value3">Text3</option>
   </select>

Now every time a user selects or changes the value of the combo box, a function named 'sel' will be called to update the variable that stores this value.

Hope this helps you. Let me know if it does.

PK

Pavan
Thanks for the reply,But its still not working.I hope it works for Onchange event but i have no idea how to retrieve using that event.Please do help me out. Thank you
SUSH
ive made adjustments to the answer please have a look. this is definitely what you are look for.
Pavan
+1  A: 

As rafl said in his comment, Perl does not have DOM events. You'd have to go through JavaScript in order to respond to this event without changing the page.

Here's how it goes: Perl creates text that gets interpreted by your browser according to the standards as they identify themselves. Since, your browser expects the base context to be an SGML/HTML document it interprets the SGML/HTML tags as document information and layout instructions. When it comes to a <script> tag, if the script identifies itself as JavaScript (or does not specify the language), the browser interprets text inside that tag as JavaScript and performs the actions specified.

Perl creates the text, only client-side script runs on your browser, completely independent from the Perl that created the text. You can communicate back to the server through forms and cookies (actually part of the HTTP protocol--the actual base context of the communication), but there has to be another request to the server. The only thing that can tell a browser what to do in response to interaction with the browser is client-side code executed by the browser.

In order to create a web application Perl (or any other server-side language) just has to create text that uses the browser capabilities to send data back to the server, so that the server-side process can read the state and generated new text that replicates the interaction.

The current way of doing this dynamically, without changing the page is through Ajax, which is basically offers the JavaScript an object to make server requests. (The idea is not totally new, we used to accomplish similar things in Java Applets, it's just that Ajax cuts out a middle man.) A good toolkit for JavaScript/Ajax is the prototype library.

Axeman