SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Guru okrogius's Avatar
    Join Date
    Mar 2002
    Location
    US
    Posts
    622
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    formField.value='x'; for a <select>

    I currently have this:
    Code:
      			var select = xGetElementById('theid');
      			for (var i = 0; i < select.length; i++) {
     				if (select.options[i].value == desiredValue) {
     		 		select.options[i].selected = true;
      				} else {
     		 		select.options[i].selected = false;
      				}
      			}
    But it only works in IE. Firefox js console complains that select doesn't have any properties. Any ideas?
    Last edited by Codename49; Mar 23, 2004 at 16:10.

  2. #2
    I'll take mine raw silver trophy MikeFoster's Avatar
    Join Date
    Dec 2002
    Location
    Alabama, USA
    Posts
    2,560
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Codename49!

    We really need to see the HTML for 'theid'.

    Is this page online?

  3. #3
    SitePoint Guru okrogius's Avatar
    Join Date
    Mar 2002
    Location
    US
    Posts
    622
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here you go Mike . (as you can see the code above is actually a slightly simplified version - the page isn't publicly only yet, but this is the copy and paste of the relevant portion)

    Code:
      	<fieldset id="timezoneShow">
     		<legend>Site Viewing Preferences</legend>		
      		<p>
     			<label for="timeZone">Timezone in which the dates will appear in.</label>
      			<select name="timeZone">
     		 	<option value="-12"<?php if ($timeZone==-12) echo ' selected="selected"'; ?>>GMT -12</option>
     		 	<option value="-11"<?php if ($timeZone==-11) echo ' selected="selected"'; ?>>GMT -11</option>
     		 	<option value="-10"<?php if ($timeZone==-10) echo ' selected="selected"'; ?>>GMT -10 (Hawaii)</option>
     		 	<option value="-9"<?php if ($timeZone==-9) echo ' selected="selected"'; ?>>GMT -9 (Alaska)</option>
     		 	<option value="-8"<?php if ($timeZone==-8) echo ' selected="selected"'; ?>>GMT -8 (Pacific Time)</option>
     		 	<option value="-7"<?php if ($timeZone==-7) echo ' selected="selected"'; ?>>GMT -7 (Mountain Time)</option>
     		 	<option value="-6"<?php if ($timeZone==-6) echo ' selected="selected"'; ?>>GMT -6 (Central Time)</option>
     		 	<option value="-5"<?php if ($timeZone==-5) echo ' selected="selected"'; ?>>GMT -5 (Eastern Time)</option>
     		 	<option value="-4"<?php if ($timeZone==-4) echo ' selected="selected"'; ?>>GMT -4 (Atlantic Time)</option>
     		 	<option value="-3"<?php if ($timeZone==-3) echo ' selected="selected"'; ?>>GMT -3 </option>
     		 	<option value="-2"<?php if ($timeZone==-2) echo ' selected="selected"'; ?>>GMT -2</option>
     		 	<option value="-1"<?php if ($timeZone==-1) echo ' selected="selected"'; ?>>GMT -1</option>
     		 	<option value="0"<?php if ($timeZone==0) echo ' selected="selected"'; ?>>GMT (Western Europe Time)</option>
     		 	<option value="1"<?php if ($timeZone==1) echo ' selected="selected"'; ?>>GMT +1 (Central Europe Time)</option>
     		 	<option value="2"<?php if ($timeZone==2) echo ' selected="selected"'; ?>>GMT +2 (Eastern Europe Time)</option>
     		 	<option value="3"<?php if ($timeZone==3) echo ' selected="selected"'; ?>>GMT +3</option>
     		 	<option value="4"<?php if ($timeZone==4) echo ' selected="selected"'; ?>>GMT +4</option>
     		 	<option value="5"<?php if ($timeZone==5) echo ' selected="selected"'; ?>>GMT +5</option>
     		 	<option value="6"<?php if ($timeZone==6) echo ' selected="selected"'; ?>>GMT +6</option>
     		 	<option value="7"<?php if ($timeZone==7) echo ' selected="selected"'; ?>>GMT +7</option>
     		 	<option value="8"<?php if ($timeZone==8) echo ' selected="selected"'; ?>>GMT +8</option>
     		 	<option value="9"<?php if ($timeZone==9) echo ' selected="selected"'; ?>>GMT +9</option>
     		 	<option value="10"<?php if ($timeZone==10) echo ' selected="selected"'; ?>>GMT +10</option>
     		 	<option value="11"<?php if ($timeZone==11) echo ' selected="selected"'; ?>>GMT +11</option>
     		 	<option value="12"<?php if ($timeZone==12) echo ' selected="selected"'; ?>>GMT +12</option>
      			</select>
      		</p>		
      	</fieldset>
      	
      	<script type="text/javascript">//<![CDATA[
      		try {
      			var d = new Date();
     			var offset = (Math.round((d.getHours()*3600+d.getMinutes()*60+d.getSeconds())/3600)-<?php echo gmdate('H',TIMENOW); ?>);
      			var select = xGetElementById('timeZone');
      			for (var i = 0; i < select.length; i++) {
     				if (select.options[i].value == offset) {
     		 		select.options[i].selected = true;
      				} else {
     		 		select.options[i].selected = false;
      				}
      			}
      			xGetElementById('timezoneShow').style.display = 'none';
      		} catch (exception) {}
      	//]]></script>
    The try {} catch() is there to surpass the firefox not working with that correctly. So if I can get rid of that and get it to work everywhere, that would be fantastic.

  4. #4
    I'll take mine raw silver trophy MikeFoster's Avatar
    Join Date
    Dec 2002
    Location
    Alabama, USA
    Posts
    2,560
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Use id='timeZone' instead of name=...


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •