Jump to content

What's the problem


Azurues

Recommended Posts

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?

Link to comment
Share on other sites

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)?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

	<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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.