1 Replies - 5060 Views - Last Post: 25 October 2009 - 11:00 PM

#1 fsloke  Icon User is offline

  • D.I.C Regular

Reputation: 25
  • View blog
  • Posts: 412
  • Joined: 19-December 07

How to post the Disabled Drop down value?

Posted 25 October 2009 - 09:03 PM

May I know How to post the Disabled Drop down value?
I cannot get the value selected in the drop down called car.

What wrong with my code?

<td class="item">
	<div class="label">Car: <span class="required">*</span>:</div><div class="message"></div>
	<select id="car">
					 <option value="Volvo" disabled selected>Volvo</option>
		</select>
		<input type="hidden" id="hCar" name="car" value=car.options[car.selectedIndex].value">
</td>



Thanks

Is This A Good Question/Topic? 0
  • +

Replies To: How to post the Disabled Drop down value?

#2 Martyr2  Icon User is offline

  • Programming Theoretician
  • member icon

Reputation: 4399
  • View blog
  • Posts: 12,255
  • Joined: 18-April 07

Re: How to post the Disabled Drop down value?

Posted 25 October 2009 - 11:00 PM

The problem is that javascript is not rendered when it prints the HTML. Javascript is client side, the HTML comes from the server. Now you can of course put in some javascript that reads the select list when you go to submit the form and puts it into the hidden form element before the form is submitted. Then that way it will be posted.

<script type="text/javascript">
function getOption() {
	var idCar = document.getElementById("hCar");
	var Car = document.getElementById("car");
	idCar.value = Car.value;
	
	document.theform.submit();
}
</script>
</head>

<body>

<form method="POST" action="" name="theform">
	<select id="car">
		<option value="Volvo" disabled selected>Volvo</option>
	</select>
	<input type="hidden" id="hCar" name="car" value=""/>

	<!-- Call the getOption javascript function which reads the select, puts the value into the hidden field and submits form -->
	<input type="button" name="getvalue" value="click" onclick="getOption()"/>
</form>



Here we use the form to call a javascript function which reads the select element, puts its value into the hidden form element and then submits the form. Hope this is what you were looking to do.

Enjoy!

"At DIC we be form submitting code ninjas... we submit many forms... of destruction!" :snap:
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1