Search Amazon.com:
Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us $3,400 per month for bandwidth bills alone, and since we don't believe in shoving popup ads to our registered users, we try to make the money back through forum registrations.
«45 »
  • Post
  • Reply
Lumpy
Apr 26, 2002

How about a twist of I gouge your fucking eyes out?

prom candy posted:

I'm so glad I'm not the only one that uses stuff like "poop" and "butt" when I'm writing psuedocode or test-cases.

I spend all day at work resisting the urge... the Cavern of COBOL is Lumpy's time!!

Adbot
ADBOT LOVES YOU

rawrr
Jul 27, 2007


Lumpy posted:

function poop() {

I wish my entire comp sci textbook was written in this tone.

darthbob88
Oct 13, 2011
Probation
Can't post for 3 days!


prom candy posted:

I'm so glad I'm not the only one that uses stuff like "poop" and "butt" when I'm writing psuedocode or test-cases.

When I was doing up a test case for a new system, I gave it a client alias of "LOLButts", short for Land o' Lakes Butter Products, headed by proud CEO L. Oliver Butterman. Didn't go anywhere beyond that, but it was fun.

No Safe Word
Feb 26, 2005

I sure do love holding onto the rock!

prom candy posted:

I'm so glad I'm not the only one that uses stuff like "poop" and "butt" when I'm writing psuedocode or test-cases.

I mean here yeah okay, but at work no...

Sulla-Marius 88
May 14, 2010



I also do dumb stuff like test with 'poop' or 'alert("you poop butts");'

Right now I'm having an issue with a .load().

code:
<script type="text/javascript">

$(document).ready(function() {
          $('#menu1').load('includes/login.inc');
		    alert(window.location.pathname);
		});
		
</script>
#menu1 exists and when i change it to $('#menu1').text("test"); it works correctly, updating the correct div as required.
The alert also works works.
includes/login.inc exists and has inside it:

code:
<?

echo "test";

?>
I've also tried replacing this with just simple "test" in plaintext, sans quotation marks, with no luck. I'm using Chrome now, I tried it on IE and no luck either.

Now, I've just changed it to load 'test.html' in the same directory, and that worked. I then changed it to 'test.inc' in the same directory, exact same contents:

code:
test<b>test</b>
And that didn't work. Save it as .php, that works. Why does .load() have such an issue with .inc files? (I need them to be .inc because I'm using .htaccess to block direct loading of those files)

Lumpy
Apr 26, 2002

How about a twist of I gouge your fucking eyes out?

Sulla-Marius 88 posted:

I also do dumb stuff like test with 'poop' or 'alert("you poop butts");'

Right now I'm having an issue with a .load().

code:
<script type="text/javascript">

$(document).ready(function() {
          $('#menu1').load('includes/login.inc');
		    alert(window.location.pathname);
		});
		
</script>
#menu1 exists and when i change it to $('#menu1').text("test"); it works correctly, updating the correct div as required.
The alert also works works.
includes/login.inc exists and has inside it:

code:
<?

echo "test";

?>
I've also tried replacing this with just simple "test" in plaintext, sans quotation marks, with no luck. I'm using Chrome now, I tried it on IE and no luck either.

Now, I've just changed it to load 'test.html' in the same directory, and that worked. I then changed it to 'test.inc' in the same directory, exact same contents:

code:
test<b>test</b>
And that didn't work. Save it as .php, that works. Why does .load() have such an issue with .inc files? (I need them to be .inc because I'm using .htaccess to block direct loading of those files)


Your are blocking requests for .inc files, then you make a GET request for an .inc file with JavaScript, which you block. This has nothing to do with jQuery or .load() knowing about or doing something 'different' with .inc files.

Sulla-Marius 88
May 14, 2010



Hm, I hadn't considered that. I'm not great at .htaccess, is there a way to limit it so that it can only be accessed through index.php? I need the main page to be able to include from it, but I don't want users to be able to access the files directly...

Suspicious Dish
Sep 24, 2011



Why not?

Sulla-Marius 88
May 14, 2010



Because the files run/display different things that shouldn't be accessed out of turn.. I can load the .inc files perfectly will within php, it's just jquery (or maybe javascript) that is restricted by the .htaccess limitation.

The Merkinman
Apr 22, 2007

I sell only quality merkins. What is a merkin you ask? Why, it's a wig for your genitals!

Thanks for that in depth explanation. I used Suspicious Dish's suggestion to just get the project done, but I'm sure I'll use that in the future and/or rewrite this project when I have time.

Suspicious Dish
Sep 24, 2011



The Merkinman posted:

Thanks for that in depth explanation. I used Suspicious Dish's suggestion to just get the project done, but I'm sure I'll use that in the future and/or rewrite this project when I have time.

I wouldn't do that. jQuery.each is perfectly sane.

Sulla-Marius 88 posted:

Because the files run/display different things that shouldn't be accessed out of turn.. I can load the .inc files perfectly will within php, it's just jquery (or maybe javascript) that is restricted by the .htaccess limitation.

Everything that JavaScript can do, somebody else can do. They can build their own HTTP client, or simply capture the traffic and send it to the other side. What does the .inc file contain that you really don't want people to access?

Sulla-Marius 88
May 14, 2010



Well it was just a lazy way of ensuring that users can't access pages or trigger functions/code that they shouldn't, by having all the divs load content from within index.php and have that be subject to a central authorisation/function-calling process.

Otherwise I have to spend far more time and energy ensuring that each process + display page is wrapped inside a conditional that breaks if the permissions aren't met (i.e. actively counteracting potential abuse, rather than just passively blocking it and only allowing calls from a single source that has already confirmed whichever (varied) conditions that it needs.

I mean the first thing that springs to mind is, if I have to remove the .htaccess file, just reproducing it by wrapping the code of every include in a conditional that checks for the existence of a variable only generated by index.php. And then that has to exist at the top of every page, which is annoying.

Lumpy
Apr 26, 2002

How about a twist of I gouge your fucking eyes out?

Sulla-Marius 88 posted:

Well it was just a lazy way of ensuring that users can't access pages or trigger functions/code that they shouldn't, by having all the divs load content from within index.php and have that be subject to a central authorisation/function-calling process.

Otherwise I have to spend far more time and energy ensuring that each process + display page is wrapped inside a conditional that breaks if the permissions aren't met (i.e. actively counteracting potential abuse, rather than just passively blocking it and only allowing calls from a single source that has already confirmed whichever (varied) conditions that it needs.

I mean the first thing that springs to mind is, if I have to remove the .htaccess file, just reproducing it by wrapping the code of every include in a conditional that checks for the existence of a variable only generated by index.php. And then that has to exist at the top of every page, which is annoying.

Adding

PHP code:
<?php defined('MYVAR') or die('OH NOES!!!');
to a few files Is certainly less annoying than a security hole.

prom candy
Dec 16, 2005

best alliance in hip-hop, waiyyohhh

Even if you do that, calling an AJAX load is going to produce the same result as trying to go to the .inc file in your browser is it not? It's not being filtered through index.php at that point, your PHP has already executed and generated your front-end content, and now your front-end content is making an AJAX call to a different file.

Physical
Sep 26, 2007

by T. Finninho


For some reason I cannot access a select tag in a sharepoint page using jquery via IE. Works fine in Chrome, not in IE. Why the hell would this be happening?

Gazpacho
Jun 18, 2004

2 MEGA 2 FAIL

A few details would be nice. IE version, jQuery code excerpt, HTML source excerpt, what your debugging shows. Things like that.

Gazpacho fucked around with this message at Jul 6, 2012 around 01:22

Sulla-Marius 88
May 14, 2010



Physical posted:

For some reason I cannot access a select tag in a sharepoint page using jquery via IE. Works fine in Chrome, not in IE. Why the hell would this be happening?

This has nothing to do with jquery but yesterday at work we noticed that IE 64-bit doesnt work well with sharepoint, toolbars etc go missing. Try using 32-bit and see if that makes a difference. It won't necessarily help your usability but it might help tracking down a fix.

Physical
Sep 26, 2007

by T. Finninho


Gazpacho posted:

A few details would be nice. IE version, jQuery code excerpt, HTML source excerpt, what your debugging shows. Things like that.
Yea I figured as much but its such a standard bit of code that it should work. It's gotta be a sharepoint problem. It works great in Chrome and not in IE sharepoint. So I was hoping someone knew of some sort of incompatibility. But here is the info you asked for.

Debugging shows nothing because IE debugger is slow as balls and impossible to use (I did check it however and there are no errors or warnings). Sharepoint Designer 2010, IE9 32-bit. And Like I said, works perfectly in chrome. I then decided to use old school DOM getElementById and even that doesn't work.

The html is a standard select with some options.
code:
<select title="Responsible Role">
   <option>Opt1</option>
   <option>Opt2</option>
   <option>Opt3</option>
</select>
code:
function RemoveNonMatchingOptionsFromSelect(fieldName, value){
	$('select[title="Responsible Role"] option').each(function () {
		alert($(this).html()); //this alert never even fires in IE
		
		if($(this).text().toLowerCase().indexOf(value.toLowerCase()) < 0 && $(this).text().toLowerCase().indexOf("none") < 0)
		{
			//alert($(this).text() + ' ' + $(this).val());
			$(this).remove();
		}
	});
}
  $(document).ready(function() { 
	RemoveNonMatchingOptionsFromSelect("Responsible Role", readCookie("ItemName"));		
});

This is suppose to run on a page that has a pop-up form where the element doesn't exist until the user clicks the add new item button. The field has a title tag of "Responsible Role" but using the sharepoint assigned id doesn't work either. I think it is because the popup window shows up later, but the document.ready fires when the new form comes up anyway so it knows to call the function on the popup render. However, I can use jquery to select items that get rendered on the first pass. I can at least select them and hide them.

Wierd thing is, I swear this worked a week ago. And I don't know or think anything changed in-between then and now.

Sulla-Marius 88 posted:

This has nothing to do with jquery but yesterday at work we noticed that IE 64-bit doesnt work well with sharepoint, toolbars etc go missing. Try using 32-bit and see if that makes a difference. It won't necessarily help your usability but it might help tracking down a fix.

I realized that a while ago and so I've been using 32-bit.

Gazpacho
Jun 18, 2004

2 MEGA 2 FAIL

If I fix value to "Opt2" then I get the missing alerts and the other options are removed, in IE8. I don't think the selector is the problem.

Physical
Sep 26, 2007

by T. Finninho


Gazpacho posted:

If I fix value to "Opt2" then I get the missing alerts and the other options are removed, in IE8. I don't think the selector is the problem.
Really?! I'm going to have to try that tommorow. When I debug the value of value I see it as whatever it is I am searching for (say Opt2) so on that end, it looked like the appropriate variable was being passed in.

edit: Well wait my alerts never fire. Are you running this in sharepoint? Because the same code works in IE9 on a non-sharepoint page. I tested it at JSfiddle. And that's what confounds the problem. The same code works in a non-sharepoint page.

edit2: Yea what you said still doesn't work for me. I think its a sharepoint problem or a configuration problem with this site. Because when you isolate this code in another page it works just fine. I wish we kept better logs of changes, because I could have sworn (and my co-worker as well) that this worked a couple weeks ago in IE. I wonder what, if anything, changed since then.

Physical fucked around with this message at Jul 6, 2012 around 20:00

stoops
Jun 11, 2001


I have this big image, not a map, just a picture. I need to be able to point to any part of the image and get some coordinates.

Right now i'm using Jquery to get the X and Y axis. Is there any way I can get the latitude/longitude? Any help or point to the right direction is appreciated.

Lumpy
Apr 26, 2002

How about a twist of I gouge your fucking eyes out?

stoops posted:

I have this big image, not a map, just a picture. I need to be able to point to any part of the image and get some coordinates.

Right now i'm using Jquery to get the X and Y axis. Is there any way I can get the latitude/longitude? Any help or point to the right direction is appreciated.

Pretty sure images don't have latitude & longitude there fella. If you are looking to do a "given a rectangle of height H and width W, if I'm at coordinate x,y in that rectangle, I want the latitude 'lat' and longitude 'lon' if the image were a map of a globe" type thing, then there's a whole lot of other questions about projections and so on to answer. Here's a Wikipedia article talking about this stuff, since I don't know squat about it: http://en.wikipedia.org/wiki/Geodetic_system

Gazpacho
Jun 18, 2004

2 MEGA 2 FAIL

e: removed, not helpful

Gazpacho fucked around with this message at Jul 18, 2012 around 01:10

Physical
Sep 26, 2007

by T. Finninho


The problem I mentioned earlier had nothing to do with jquery, apparently IE and sharepoint render DropDowns that have 20+ options in a very esoteric way! Oh my god it is so stupid. http://sympmarc.com/2010/05/19/two-...orms-dropdowns/

EVGA Longoria
Dec 25, 2005

Let's go exploring!


Is there anything unusual with the Animate function, specifically regarding changing the color property?

I'm using [url=http://jsoverson.github.com/jquery.pulse.js/]jquery.pulse.js[/url[ to loop an animation to change the color of some text. It's specifically shown in the examples, and works great on the sample page.

When I try to do it on my sandbox page, it's not working how you'd expect.

If I tell it to animate the opacity, it works fine. If I tell it to animate the color, nothing happens. The script triggers and runs for the correct amount of time, I've confirmed that with callbacks, but nothing changes on the items I'm trying to change. It happens even if I add color into an opacity one -- the opacity doesn't change, nor does the color. It just sits like a lump.

Seeing as pulse is basically a loop for animate, I decided to try that out to see if anything happens there. Still no joy -- the animate works fine for opacity or fontSize, does not change anything for color. Same thing for background-color -- doesn't do a damned thing.

At this point, I'm stumped. Barring it being Bootstrap related, I have no idea what could be causing colors not to trigger.

code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>

<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="">

<title>OB10 Technical Operations Dashboard</title>

<link rel="stylesheet" href="http://localhost:3000/bootstrap/css/bootstrap.css" >
<link rel="stylesheet" href="http://localhost:3000/fontawesome/css/font-awesome.css" >
<link rel="stylesheet" href="http://localhost:3000/css/style.css" >
<link rel="stylesheet" href="http://localhost:3000/css/ffd.css" >

<!--/*
dark blue = rgb(0,50,116)
light blue= rgb(0,152,216)
orange =  rgb(238,125,17)
*/-->

<script src="javascripts/jquery-1.7.2.min.js"></script>
<script src="bootstrap/js/bootstrap.min.js"></script>
<script src="javascripts/tempo.js"></script>
<script src="javascripts/jquery.pulse.js"></script>

</head>
<body>

<!--NavBar for future usage-->

<div class="navbar">

  <div class="navbar-inner">

    <div class="container">

	<h5><a class="brand" href="http://localhost:3000">Monitoring Dashboard</a></h5>

	<ul class="nav">

	<li><a href="http://localhost:3000/invoice">Invoicing</a></li>

	<li><a href="http://localhost:3000/po">Purchase Orders</a></li>

	<li><a href="http://localhost:3000/oms">OMS</a></li>

	</ul>

    </div>

  </div>

</div>

<div class="container">

	<div class="row">

		<div class="alerts span4">

			<i class="icon-circle-arrow-up pull-left alerts" style="color: #FF0000;" id="testIcon"></i>  <p class="alerts" id="testText">Test</p>

		</div>

	</div>

</div>



<style>



div.alerts {

	font-size: 100px;

	line-height: 100px;

}



i.alerts {

	padding-top: 5px;

	margin-right: 20px;

}



p.alerts {

	font-size: 72px;

	vertical-align: middle;

}



</style>



<script>



$(document).ready(function()

{

console.log("Pulsing!");

var pi = $('#testText')



// pi.pulse(

// 	{

// 		opacity : 0.5

// 	},

// 	{

// 		returnDelay : 500,

// 		interval : 1000,

// 		pulses : 10

// 	}

// );



pi.animate({

	color: "green"}, 1000

);





})

</script>

</body>
</html>

Lumpy
Apr 26, 2002

How about a twist of I gouge your fucking eyes out?

Casao posted:

Is there anything unusual with the Animate function, specifically regarding changing the color property?


My memory is terrible, or it might have changed in the last couple years, but I don't think you can use 'named' colors in animate.

Alligator
Jun 10, 2009

LOCK AND LOAF


Casao posted:

Is there anything unusual with the Animate function, specifically regarding changing the color property?
jquery doesn't support color animation on it's own.

including something like this would make it work without any changes to your code.

EVGA Longoria
Dec 25, 2005

Let's go exploring!


Lumpy posted:

My memory is terrible, or it might have changed in the last couple years, but I don't think you can use 'named' colors in animate.

I've tried the hex codes (no luck) and using the rgb(#,#,#) which just returns "rgb is not defined" as well.

EVGA Longoria
Dec 25, 2005

Let's go exploring!


Alligator posted:

jquery doesn't support color animation on it's own.

including something like this would make it work without any changes to your code.

Thanks a ton. I don't know how the hell the examples are working, I looked through the page for any other plugins before I asked. This works perfectly.

aBagorn
Aug 26, 2004


Hi jquery thread!

So I got my first ever job programming, and there's a bit of jquery involved. I've been teaching myself to get up to speed, but now have a question.

I have a page (ASP.NET MVC 3) that will either have 2 or 3 tables on it, which is dependent on one field of data from our database. I want to show or hide that third table dynamically based on the value of that field. I know how I would do it in C# codebehind:

C# code:
protected void ShowACHGrid()
    {
        if (polmast.GRP == "ACH")
            achGrid.Visible = true;
        else achGrid.Visible = false;
    }
How would I do the same sort of thing in jQuery?

edit: \/will that work if I'm using the datatables plugin?
also, my main question was how to access the "polmast" variable, which is instantiated outside the script

aBagorn fucked around with this message at Jul 23, 2012 around 19:01

Suspicious Dish
Sep 24, 2011



Javascript code:
if (polmast.GRP === "ACH")
    achGrid.show();
else
    achGrid.hide();

Funking Giblet
Jun 28, 2004

Jiglightful!

MVC3, use ViewModel to set a bool ShowACH or whatever, bind this in your ModelBinder or before you return your view.

In your view

code:
@if(Model.ShowACH)
{
	//Some html or template/view
}

fletcher
Jun 27, 2003

ken park is my favorite movie

Should I be using .prop() now instead of .attr() for things like "disabled" and "checked" ?

Funking Giblet
Jun 28, 2004

Jiglightful!

Neither, they both have an exposed property for the DOM element.
el.checked = false;
el.disabled = true;

Deus Rex
Mar 4, 2005

Neither snow nor rain nor heat nor gloom of Aftermath stays this courier from the swift completion of his appointed VSATs.


Funking Giblet posted:

Neither, they both have an exposed property for the DOM element.
el.checked = false;
el.disabled = true;

what? do you mean to say that this:

Javascript code:
$('input').each(function() { this.checked = true; });
is better/clearer than this:

Javascript code:
$('input').prop('checked', true);

Funking Giblet
Jun 28, 2004

Jiglightful!

Deus Rex posted:

what? do you mean to say that this:

Javascript code:
$('input').each(function() { this.checked = true; });
is better/clearer than this:

Javascript code:
$('input').prop('checked', true);

elem.checked is easier / safer than
$(elem).prop("checked")

If it comes to multiple elements, the first way is safer and quicker, the second way easier to write. Choose safer each time.

aBagorn
Aug 26, 2004


Guys, I'm a goddamn jQuery mess

I just can't seem to wrap my head around it, and I don't know why.

The long and the short of it is that I have a page with a table listing all the claims made on an insurance policy. I want to create a link on the claim number that will open a modal that will display details about that claim.

So I know I'm going to have to do something like

code:
        $('#ClaimDialog').dialog({
            autoOpen: false, width: 800, resizable: true, modal: true
        });
but then I'm lost on opening it, because (in my MVC) I'm doing a foreach to display the table dynamically and I'm not sure how to pass the ClaimID as a parameter in the .live("click", function() part

German Joey
Dec 18, 2004


aBagorn posted:

Guys, I'm a goddamn jQuery mess

I just can't seem to wrap my head around it, and I don't know why.

The long and the short of it is that I have a page with a table listing all the claims made on an insurance policy. I want to create a link on the claim number that will open a modal that will display details about that claim.

So I know I'm going to have to do something like

code:
        $('#ClaimDialog').dialog({
            autoOpen: false, width: 800, resizable: true, modal: true
        });
but then I'm lost on opening it, because (in my MVC) I'm doing a foreach to display the table dynamically and I'm not sure how to pass the ClaimID as a parameter in the .live("click", function() part

First of all, take a look at this demo, which should help you get started with creating an embedded dialog form: http://jqueryui.com/demos/dialog/#modal-form

Second of all, the dialog itself doesn't really take parameters, it simply opens the dialog. It sounds like what you want is to pass along the claimID before the dialog actually opens, either through .data or just by modifying the form itself. In the latter case, perhaps something like this, assuming that the demo is modified like so:

  • We change the dialog-form div to this:
    code:
        <div id="dialog-form" title="Create new user">
            <p class="validateTips">Please enter data for claim ID <span id="claimID_label"></span>. All form fields are required.</p>
            <form>
            <fieldset>
                <input type="hidden" name="claimID_value" id="claimID_value"/>
                <label for="name">Name</label>
                <input type="text" name="name" id="name" class="text ui-widget-content ui-corner-all" />
                <label for="email">Email</label>
                <input type="text" name="email" id="email" value="" class="text ui-widget-content ui-corner-all" />
                <label for="password">Password</label>
                <input type="password" name="password" id="password" value="" class="text ui-widget-content ui-corner-all" />
            </fieldset>
            </form>
        </div>
    
    (I just added some extra text to the "validateTips" paragraph and a hidden element in the form.)

  • We add an input element: <input type="text" name="claimID" id="claimID"/> right after the "Create new user" button.

Then we can do:
code:
    $( '#create-user' ).button().click(function() {
        $('#claimID_label').text() = $('#claimID').value;
        $('#claimID_field').value = $('#claimID').value;
        $('#dialog-form' ).dialog( "open" );
    });
Changing the code so that the claimID also shows up in the output table can be an excerise for you. :o)

Apok
Jul 22, 2005
I have a title now!

Hello, I am having a problem with code that checks a value passed through a URL. The url looks like this:

code:
http://127.0.0.1/zip/test.html?email=blah@blahblah.com&zipcode=77071
I use a JQuery function to get information from the URL:

code:
function gup(name){
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return "";
  else
    return unescape(results[1]);
}
Then I introduce an array with several hundred zip codes and run a loop to check for a match. The zip codes represent local zip codes, and the code is supposed to check a box for a local or national email newsletter.

code:
		
var zipCode = new Array ;
  zipCode[0] = "77002" ;
  zipCode[1] = "77003" ;

//and so forth up to zipCode[218]

var urlZip = gup('zipcode').value ;
			
  outofloop:

  for( var i = 0 ; i <= 219; i++ ) {
				
    if( zipCode[i] == urlZip ) {
					
      document.getElementById('Temp_HOUSTON_STORE_EMAILS_FIELD').checked = 1;
					
      break outofloop;

    }
				
    if( i == 219 ) {
					
      document.getElementById('Temp_ONLINE_NATIONAL_EMAILS_FIELD').checked = 1;
					
      break outofloop;
					
    }
				
document.getElementById('Temp_PERSONAL_PRODUCT_EMAILS_FIELD').checked = 1;
document.getElementById('Temp_CLEARANCE_SALES_FIELD').checked = 1;
document.getElementById('Temp_NEW_PRODUCTS_FIELD').checked = 1;
document.getElementById('Temp_PRODUCT_REVIEW_EMAILS_FIELD').checked = 1;
						
  }
	
}
My problem is that even if I enter a zip code (such as 99999) which is not found in the array, the function will return the first if statement. What am I missing here? I've read up on for statements and figure I probably missed something very important, but I have no idea what that would be.

I've tried a break to outside of the for loop, I've tried removing .value from after the var. I'm just lost at this point.

Apok fucked around with this message at Jul 30, 2012 around 21:07

Adbot
ADBOT LOVES YOU

Bhaal
Jul 13, 2001
I ain't going down alone

Is that the actual code or just a quick mockup of it? If I'm reading that correctly, you want to set Temp_HOUSTON_STORE_EMAILS_FIELD to checked if the zip does exist in the array, and set Temp_ONLINE_NATIONAL_EMAILS_FIELD if it's not in the array. You also want to set 4 other fields to checked but I'm not sure why they're in the loop body.

There's far better ways to structure that loop, but because the array and what you want to do with it is so simple you can forget the loop entirely and just do this instead:
Javascript code:
if( $.inArray(urlZip, zipcode) < 0) // zip NOT in the array
{
    document.getElementById('Temp_ONLINE_NATIONAL_EMAILS_FIELD').checked = 1;
}
else
{
     document.getElementById('Temp_HOUSTON_STORE_EMAILS_FIELD').checked = 1;
}
				
document.getElementById('Temp_PERSONAL_PRODUCT_EMAILS_FIELD').checked = 1;
document.getElementById('Temp_CLEARANCE_SALES_FIELD').checked = 1;
document.getElementById('Temp_NEW_PRODUCTS_FIELD').checked = 1;
document.getElementById('Temp_PRODUCT_REVIEW_EMAILS_FIELD').checked = 1;
EDIT: Also, using the selector would be cleaner / more consistent like $('#Temp_ONLINE_NATIONAL_EMAILS_FIELD').attr('checked','checked') (or prop()) but that's nitpicking outside of your question.

Bhaal fucked around with this message at Jul 30, 2012 around 22:01

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply
«45 »