2 Replies - 313 Views - Last Post: 03 May 2013 - 01:55 PM

#1 allinol  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 03-May 13

Javascript - Firefox and IE question

Posted 03 May 2013 - 12:40 PM

Try to get text box expanding based on selected drop down value based on stylesheet. following code works fine in firefox doesnot support IE. Does any one know what is conflicting with the browser.
<script type="text/javascript">
	$(document).ready(function (){
		var optSlct = $('#nav-search-in').find("option:selected").text();
		var optSlct ='Products';
		rsizeText();
		if(optSlct != 'Products'){
			$('#displaylabel').html(optSlct);
			rsizeText();
		}
	});
	var facade = $("#nav-search-in");
	var searchBox = $(".nav-searchfield-width");
	var srchBoxParent = (function(elem){if(elem.hasClass("nav-searchfield-width-fluid")){return elem;}else{if(elem.parent().size()>0){return arguments.callee(elem.parent());}else{return searchBox.parent();}}}(searchBox));
	var rsizeText = function(){
		srchBoxParent.css({"padding-left":facade.width()});
		searchBox.css("padding-left",parseInt(searchBox.css("padding-left"),0)?0:1);
	}
	$('#searchDropdownBox').change(function (){
		var slctOpt = this.options[this.selectedIndex];
		$('#displaylabel').html(slctOpt.text);
		rsizeText();
		searchBox.focus();
	});
	
	
</script>


This post has been edited by macosxnerd101: 03 May 2013 - 12:41 PM
Reason for edit:: Please use code tags


Is This A Good Question/Topic? 0
  • +

Replies To: Javascript - Firefox and IE question

#2 andrewsw  Icon User is offline

  • Fire giant boob nipple gun!
  • member icon

Reputation: 2875
  • View blog
  • Posts: 9,540
  • Joined: 12-December 12

Re: Javascript - Firefox and IE question

Posted 03 May 2013 - 01:49 PM

Is this code positioned at the bottom of the page, before the closing body-tag? Otherwise, the code from here:

var facade = $("#nav-search-in");

onwards may be trying to refer to elements that do not yet exist on the page.

Are there errors in the browsers console? If you don't know what this is, refer to my signature.
Was This Post Helpful? 0
  • +
  • -

#3 andrewsw  Icon User is offline

  • Fire giant boob nipple gun!
  • member icon

Reputation: 2875
  • View blog
  • Posts: 9,540
  • Joined: 12-December 12

Re: Javascript - Firefox and IE question

Posted 03 May 2013 - 01:55 PM

I suspect this:

slctOpt.text
might be an issue. Rather than the text property (which may not exist) you should use either (jQuery) val() or text().

This may be an issue in this line as well:

var optSlct = $('#nav-search-in').find("option:selected").text();

Note: The text() and val() of an option are not necessarily the same.

This post has been edited by andrewsw: 03 May 2013 - 01:58 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1