3 Replies - 2946 Views - Last Post: 07 August 2009 - 09:53 PM

#1 Kruithne  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 99
  • View blog
  • Posts: 442
  • Joined: 28-July 09

Select Box Validation

Post icon  Posted 06 August 2009 - 03:05 AM

Hey, I've been messing about with this Javascript select box validation and I can't get it to work.

At the moment all I want to do is alert the selectIndex value of the select box.

java script:
function checkSelection(){
var selBox = document.dateSelect.selectDate;
selected=selBox.options[selectBox.selectedIndex].value;
alert(selected);
}



Form:
<form name="dateSelect" method="post" action="date.php">
<select name="selectDate">
<option value="selDate" selected>Select a date...</option>
<option value="1_0730509102009">Friday 9th October 2009 (189 tickets available)</option>
<option value="1_0730610102009">Saturday 10th October 2009 (189 tickets available)</option>
</select></form>

<span onclick="checkSelection()">Here</span>



The option values and texts are filled out by a PHP script and I'm using a <span> to trigger the funtion.

Any help would be greatly appreciated as to why this isn't working! :)

Is This A Good Question/Topic? 0
  • +

Replies To: Select Box Validation

#2 noorahmad  Icon User is offline

  • Untitled
  • member icon

Reputation: 209
  • View blog
  • Posts: 2,290
  • Joined: 12-March 09

Re: Select Box Validation

Posted 06 August 2009 - 03:19 AM

try this:
<script type="text/javascript">
function checkSelection(){
var selBox = document.getElementById('selectDate');
alert(selBox.value);
}
</script>
<form name="dateSelect" method="post" action="date.php" id="dateSelect">
<select name="selectDate" id="selectDate">
<option value="selDate" selected>Select a date...</option>
<option value="1_0730509102009">Friday 9th October 2009 (189 tickets available)</option>
<option value="1_0730610102009">Saturday 10th October 2009 (189 tickets available)</option>
</select></form>

<span onclick="checkSelection()">Here</span>
<a href="#" onclick="checkSelection()">Here</a>


:)
Was This Post Helpful? 1
  • +
  • -

#3 Kruithne  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 99
  • View blog
  • Posts: 442
  • Joined: 28-July 09

Re: Select Box Validation

Posted 06 August 2009 - 03:53 AM

Cheers noorahmad, worked like a charm! :D
Was This Post Helpful? 0
  • +
  • -

#4 noorahmad  Icon User is offline

  • Untitled
  • member icon

Reputation: 209
  • View blog
  • Posts: 2,290
  • Joined: 12-March 09

Re: Select Box Validation

Posted 07 August 2009 - 09:53 PM

You are welcome :^:
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1