Jump to content

<select> not displaying properly


shaunmckinnon

Recommended Posts

when I parse it shows in firefox the select box, but won't let it be selectable.  in explorer it just shows AMPM side by side with now select box.  Can't figure out what I've done wrong.  Here's the code:

<html>
<head>
<title>test</title>
  <script>
    function createTimeSelect(id){
  document.getElementById(id).innerHTML=""
  							+"<input type='text' id='' name='' value='hour' size='6'>"
							+":"
							+"<input type='text' id='' name='' value='minutes' size='6'"
							+"<select id='' name=''>"
							+"<option value=''>AM</option>"
							+"<option value=''>PM</option>"
							+"</select>";
}
  </script>
</head>
<body>
  <span id="timeSelectField" onClick="createTimeSelect(this.id);">***click here to select the time***</span>
</body>
</html>

 

Thanks,

Shaun

Link to comment
https://forums.phpfreaks.com/topic/113087-not-displaying-properly/
Share on other sites

sorry, i fixed that.  it's still doing the same thing now in both firefox and internet explorer.  it shows the select box but when you attempt to make a selection it closes the box on you and doesn't allow it.  in fact when you click the arrow, the drop down box recede's immediately.

Thats because you already have a click event on the div which is re-writing it again your code should be

 

<html>
<head>
<title>test</title>
  <script>
  var createItem = 0;
    function createTimeSelect(id){
if (createItem==0)
{
  document.getElementById(id).innerHTML=""
  							+"<input type='text' id='' name='' value='hour' size='6'>"
							+":"
							+"<input type='text' id='' name='' value='minutes' size='6'"
							+"<select id='test' name='test'>"
							+"<option value=''>AM</option>"
							+"<option value=''>PM</option>"
							+"</select>";
							createItem=1;
}
}
  </script>
</head>
<body>
  <span id="timeSelectField" onClick="createTimeSelect(this.id);">***click here to select the time***</span>
</body>
</html>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.