Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript
Javascript General Javascript discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old February 8th, 2005, 05:29 PM
Registered User
Join Date: Aug 2004
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default can't read value from select tag using javascript

Hi to All,

           When i try to read value from the select tag ,show the "undefine error".

pls check any one and reply me...

echo "<html><title> welcome to php </title><body bgcolor='orange'>";
$design_table="<table border='1'> <tr> <td>xxx </td> <td> ddfff</td> </tr>

echo $design_table;
echo "<script language='javascript'>
           function ck()
                  alert('welcome to php'+window.cname.value);
          function lis()

                          alert('Select item is:' + window.item.value);

echo "<input type=text name='cname' size=10>"."<br>"."<input type=password name='pwd'>

     <input type=button value='click me' onclick='ck()'>";

echo "<br> <select name='item'>
                    <option value='0' >Dosai
                    <option value='1' selected>Idle
        <option value='2'>Uthappam
       <option value='3'>Rice
      <option value='4'>Vadai
echo "<input type=button value='check val' onclick='lis()'>";
echo "</body>"."</html>";
Old February 8th, 2005, 07:08 PM
Friend of Wrox
Join Date: May 2004
Posts: 642
Thanks: 0
Thanked 43 Times in 42 Posts

You will not get value by window.item.value

you need to add document.form-name.item.value or use getelementbyid.

Om Prakash
Old February 9th, 2005, 11:18 PM
Friend of Wrox
Join Date: Nov 2003
Posts: 1,285
Thanks: 0
Thanked 2 Times in 2 Posts

Put your form elements into a form and refer to the select element value by document.forms.YOUR_FORM_ID.item.options[document.forms.YOUR_FORM_ID.item.selectedIndex].value.


-Snib - http://www.snibworks.com
Where will you be in 100 years?

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to select only the parent tag and ignore the c Prem Rajesh Kumar XSLT 3 November 6th, 2007 12:53 PM
HTML tag from C# or ASP.NET tag from javascript angshujit ASP.NET 2.0 Basics 3 February 16th, 2007 10:07 AM
Quest: How to select the second tag?! gnesland XSLT 4 November 28th, 2006 11:09 AM
get displayed name of the <select> tag nikeshkm HTML Code Clinic 1 October 20th, 2006 11:21 PM
Dynamic Select Tag fs22 Javascript How-To 1 December 15th, 2004 08:32 PM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.