Page 1 of 1

Form validation (problem with SELECT value)

Posted: Tue Sep 02, 2008 8:54 am
by wasir
I am struggling with getting select-->option value in pop up message box.

my javascript

Code: Select all

 
<SCRIPT LANGUAGE=JAVASCRIPT>
function verify(){
       msg = "Please verify the building you selected is " + document.report.building.selectedIndex + "\n\n If this is correct, click 'OK'"
       return confirm(msg);
}
</SCRIPT>
 
my form

Code: Select all

<form name="report" action="process.php5" method="POST" onSubmit="return verify()">
my select tag

Code: Select all

<select name="building" id="building">
<?php
                    
// getting the building name
if (!$resultbldng = @mysqli_query($link, 'SELECT * FROM tbl_bldngname WHERE sno<>\'18\' AND current=\'1\' ORDER BY `name` ASC')) {
  echo '<p class=err>Error: ' . mysqli_error($link) . '.</p>';
  exit;
}
mysqli_data_seek($resultbldng, 0);
while ($rowbldng = mysqli_fetch_assoc($resultbldng)) {
    print '<option value='.$rowbldng['sno'];
    print ' ';
    print($_SESSION['building']==$rowbldng['sno']?'SELECTED':'').' >'.$rowbldng['name'].'</option>';
}
?>                  
</select>
I don't know why it's showing undefined in the message pop up.
Image

Please help!!!

Re: Form validation (problem with SELECT value)

Posted: Tue Sep 02, 2008 9:17 am
by jayshields
document.getElementById('building').text will probably be what you want.
http://www.mredkj.com/tutorials/tutorial002.html

Re: Form validation (problem with SELECT value)

Posted: Tue Sep 02, 2008 9:55 pm
by wasir
Thanks for your reply Jay.

I tried document.getElementById('building').text
but even that's giving undefined output

Re: Form validation (problem with SELECT value)

Posted: Tue Sep 02, 2008 11:22 pm
by wasir
:oops:
my mistake.
Select tag name (building) was getting interfered with another script. Changing the name has fixed the issue...