Azurues Posted February 11, 2011 Share Posted February 11, 2011 Hey. This is my script: <script type="text/javascript"> var slot1=<?php echo $slot1;?>; var slot2=<?php echo $slot2;?>;etc... etc... $().ready( function () { $(function() { $('[id^=info]').dialog({ dialogClass: 'notitle', autoOpen: false, width: '75', height: 'auto', resizable: false }); }); $('[id^=slot]').mouseover(function() { var slotIdPrefix = 'slot'; var slotNum = $(this).attr('id').substring((slotIdPrefix.length)); var slotOffset = $('#slot' + slotNum).offset(); var slotWidth = $('#slot' + slotNum).width(); var dialogWidth = $('#info' + slotNum).dialog('option', 'width'); $('#info' + slotNum).dialog('option','position',[slotOffset.left+slotWidth+153-dialogWidth,slotOffset.top+32-$(window).scrollTop()]); [b]if ($(slot.concat(slotNum))>0)[/b]{ $('#info' + slotNum).dialog('open'); } }); $('[id^=slot]').mouseout(function() { $('[id^=info]').dialog('close'); }); }); The bolded part seems to be wrong because no dialog appears at all. Anyone can help me with that, how should I change the if part? Quote Link to comment https://forums.phpfreaks.com/topic/227347-whats-the-problem/ Share on other sites More sharing options...
Adam Posted February 11, 2011 Share Posted February 11, 2011 That expression will never evaluate to true because .contact() returns a copy of the merged arrays. Are you wanting to check against a successful merge, or that the size / "length" of the merged arrays is more than 0? Quote Link to comment https://forums.phpfreaks.com/topic/227347-whats-the-problem/#findComment-1172672 Share on other sites More sharing options...
Azurues Posted February 11, 2011 Author Share Posted February 11, 2011 Yes, I have slot variables up to 30 and want to check if the variable on which mouse hovered is more than 0,. Quote Link to comment https://forums.phpfreaks.com/topic/227347-whats-the-problem/#findComment-1172679 Share on other sites More sharing options...
Adam Posted February 11, 2011 Share Posted February 11, 2011 Okay. You need to use the .length property then: if (slot.concat(slotNum).length > 0) By the way you also had the expression placed within a jQuery selector? Removed it. Quote Link to comment https://forums.phpfreaks.com/topic/227347-whats-the-problem/#findComment-1172681 Share on other sites More sharing options...
Azurues Posted February 11, 2011 Author Share Posted February 11, 2011 Changed variable names to slots and added the .length property. Dialog still doesn't open . Quote Link to comment https://forums.phpfreaks.com/topic/227347-whats-the-problem/#findComment-1172683 Share on other sites More sharing options...
Adam Posted February 11, 2011 Share Posted February 11, 2011 I didn't look far away from that one statement before, but you seem to have a series of problems with this code. Where do you define slot (or slots)? What's it supposed to be? .concat() is a method of an array object, so slot should be an array. From what I can tell it will be undefined. var slotNum = $(this).attr('id').substring((slotIdPrefix.length)); The .substring() start parameter starts from 0, so settings it to the length of the prefix will actually be 1 character ahead than you're expecting. slot.concat(slotNum) .concst() expects one or more arrays passed as parameter(s), where as you're passing the string (as mentioned above) so I imagine it's throwing an error. Can you explain what you're trying to do with this code, and what logic should be (in English)? Quote Link to comment https://forums.phpfreaks.com/topic/227347-whats-the-problem/#findComment-1172710 Share on other sites More sharing options...
Azurues Posted February 11, 2011 Author Share Posted February 11, 2011 Slots are defined at the second line. var slots1=<?php echo $slot1;?>; var slots2=<?php echo $slot2;?>;etc... etc... They're numeric strings picked from a sql database, though non arrays, I used concat just to see if it would work, don't really know javascript too well. The problem as mentioned is the if part. For comparison I want to use the slots variable and add the same number as I'm using for the dialog (info) selector. So if dialog's selector is info30 it should use slots30 for comparison. Quote Link to comment https://forums.phpfreaks.com/topic/227347-whats-the-problem/#findComment-1172954 Share on other sites More sharing options...
Azurues Posted February 13, 2011 Author Share Posted February 13, 2011 Bump Anyone? Quote Link to comment https://forums.phpfreaks.com/topic/227347-whats-the-problem/#findComment-1173541 Share on other sites More sharing options...
haku Posted February 13, 2011 Share Posted February 13, 2011 At a quick glance, this: $().ready( function () { Should be this: $(document).ready( function () { I don't know if that's where your problem lies though, I'm not too clear on what exactly your problem is. Quote Link to comment https://forums.phpfreaks.com/topic/227347-whats-the-problem/#findComment-1173561 Share on other sites More sharing options...
Azurues Posted February 13, 2011 Author Share Posted February 13, 2011 The problem is as MrAdam said, the concat method. Again, I used it just to try if it would work, it's not the way I necessarily want to do it. The thing I want is to add a number . I have variables called slots. They go: slots1 slots2 slots3 etc... And in the if part I want to select a slots variable with the same number as slotNum is. So if slotNum is 5 I want to select slots5 variable and compare it. The thing is I do not know how to do so and I'm asking if anyone could help me with that :S Quote Link to comment https://forums.phpfreaks.com/topic/227347-whats-the-problem/#findComment-1173589 Share on other sites More sharing options...
haku Posted February 13, 2011 Share Posted February 13, 2011 Show us your current code, including the OUTPUT of the PHP (don't show the PHP). You have obviously made some changes since this thread started. Also, my previous post still stands. Your ready function was incomplete. Quote Link to comment https://forums.phpfreaks.com/topic/227347-whats-the-problem/#findComment-1173661 Share on other sites More sharing options...
Azurues Posted February 13, 2011 Author Share Posted February 13, 2011 <script type="text/javascript"> var slots1=<?php echo $slot1;?>; var slots2=<?php echo $slot2;?>;var slots3=<?php echo $slot3;?>; var slots4=<?php echo $slot4;?>; var slots5=<?php echo $slot5;?>; var slots6=<?php echo $slot6;?>; var slots7=<?php echo $slot7;?>; var slots8=<?php echo $slot8;?>; var slots9=<?php echo $slot9;?>; var slots10=<?php echo $slot10;?>; var slots11=<?php echo $slot11;?>; var slots12=<?php echo $slot12;?>; var slots13=<?php echo $slot13;?>; var slots14=<?php echo $slot14;?>; var slots15=<?php echo $slot15;?>; var slots16=<?php echo $slot16;?>; var slots17=<?php echo $slot17;?>; var slots18=<?php echo $slot18;?>; var slots19=<?php echo $slot19;?>; var slots20=<?php echo $slot20;?>; var slots21=<?php echo $slot21;?>; var slots22=<?php echo $slot22;?>; var slots23=<?php echo $slot23;?>; var slots24=<?php echo $slot24;?>; var slots25=<?php echo $slot25;?>; var slots26=<?php echo $slot26;?>; var slots27=<?php echo $slot27;?>; var slots28=<?php echo $slot28;?>; var slots29=<?php echo $slot29;?>; var slots30=<?php echo $slot30;?>; $(document).ready( function () { $(function() { $('[id^=info]').dialog({ dialogClass: 'notitle', autoOpen: false, width: '75', height: 'auto', resizable: false }); }); $('[id^=slot]').mouseover(function() { var slotIdPrefix = 'slot'; var slotNum = $(this).attr('id').substring((slotIdPrefix.length)); var slotOffset = $('#slot' + slotNum).offset(); var slotWidth = $('#slot' + slotNum).width(); var dialogWidth = $('#info' + slotNum).dialog('option', 'width'); $('#info' + slotNum).dialog('option','position',[slotOffset.left+slotWidth+153-dialogWidth,slotOffset.top+32-$(window).scrollTop()]); if ($('slots' + slotNum) > 0){ $('#info' + slotNum).dialog('open'); } }); $('[id^=slot]').mouseout(function() { $('[id^=info]').dialog('close'); }); }); </script> Almost no changes since I didn't have much time. The if part at the end is another failed try of mine to get what I want, again, I'm not experienced at js and that is the only thing where I need help, adding the a number to the end of slots prefix and using it as a variable to compare. Output with the if part: http://sciencewar.hostme.lt/images/inv.bmp (mouse is over an item which should bring out the dialog) Output without the if: http://sciencewar.hostme.lt/images/inv2.bmp This is how it should be but the problem is that it still brings out the dialog on slots(those squares) where there aren't any items(pictures), that is why I want to use the if part, each item has a value which is stored in each slots variable. Quote Link to comment https://forums.phpfreaks.com/topic/227347-whats-the-problem/#findComment-1173673 Share on other sites More sharing options...
haku Posted February 13, 2011 Share Posted February 13, 2011 What are you actually trying to do? Quote Link to comment https://forums.phpfreaks.com/topic/227347-whats-the-problem/#findComment-1173679 Share on other sites More sharing options...
Azurues Posted February 13, 2011 Author Share Posted February 13, 2011 The thing I want is to add a number . I have variables called slots. They go: slots1 slots2 slots3 etc... And in the if part I want to select a slots variable with the same number as slotNum is. So if slotNum is 5 I want to select slots5 variable and compare it. The thing is I do not know how to do so and I'm asking if anyone could help me with that :S Quote Link to comment https://forums.phpfreaks.com/topic/227347-whats-the-problem/#findComment-1173681 Share on other sites More sharing options...
jcanker Posted February 14, 2011 Share Posted February 14, 2011 It sounds to me like you're trying to create dynamic variable names. I'm not sure if jQuery can handle dynamic variable names. You have: if ($('slots' + slotNum) > 0){ $('#info' + slotNum).dialog('open'); javascript, however, can handle dynamic variables. From http://www.hiteshagrawal.com/javascript/dynamic-variables-in-javascript var data = "testVariable"; eval("var temp_" + data + "=123;"); alert(temp_testVariable); creates a variable named "temp_testVariable" and assigns the value of 123. Part of your problem may be that you haven't declared var before naming the variable, but I'm not sure. Quote Link to comment https://forums.phpfreaks.com/topic/227347-whats-the-problem/#findComment-1173945 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.