Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New to the CF scene
    Join Date
    Jun 2010
    Posts
    9
    Thanks
    1
    Thanked 1 Time in 1 Post

    Combining String in Javascript

    I am throughly confused....why does this seemingly simple deal not work?

    Code:
    <script type="text/javascript">
    <!--
    window.onbeforeunload = function (){
    	var checkboxImg = new Image();
    	var checkboxImgUrl = "checkbox.php%3Flonger%3D" + reviews-chk-longer.checked +
                    "%26discrete%3D" + reviews-chk-discrete.checked + 
                    "%26natural%3D" + reviews-chk-natural.checked +
                    "%26thicker%3D" + reviews-chk-thicker.checked +
    		"%26permanent%3D" + reviews-chk-permanent.checked +
    		"%26stamina%3D" + reviews-chk-stamina.checked +
    		"%26harder%3D" + reviews-chk-harder.checked +
    		"%26vascularity%3D" + reviews-chk-vascularity.checked +
    		"%26drive%3D" + reviews-chk-drive.checked +
    		"%26guarantee%3D" + reviews-chk-guarantee.checked +
    		"%26trials%3D" + reviews-chk-trials.checked +
    		"%26affordable%3D" + reviews-chk-affordable.checked;
    	alert(checkboxImgUrl);
    	checkboxImg.src = checkboxImgUrl;
    }
    // -->	
    </script>
    I get no alert when I do this....however the same thing without all of the added strings works fine, ie:

    Code:
    <script type="text/javascript">
    <!--
    window.onbeforeunload = function (){
    	var checkboxImg = new Image();
    	var checkboxImgUrl = "checkbox.php";
    	alert(checkboxImgUrl);
    	checkboxImg.src = checkboxImgUrl;
    }
    // -->	
    </script>
    Can anyone please help? I tried using .concat and that didn't help either
    Last edited by serjsagan; 06-11-2010 at 09:17 PM.

  • #2
    Senior Coder tomws's Avatar
    Join Date
    Nov 2007
    Location
    Arkansas
    Posts
    2,644
    Thanks
    29
    Thanked 330 Times in 326 Posts
    ***** pill spammer, eh? I think I'll let this one pass.
    Are you a Help Vampire?

  • #3
    New to the CF scene
    Join Date
    Jun 2010
    Posts
    9
    Thanks
    1
    Thanked 1 Time in 1 Post
    Nope, no spamming...I have exhausted all of my research and and am thoroughly stuck...I have even considered trying to drop this all together and go with sessions, but that seems to be an impossibility with getting javascript variables into php session variables...your response makes me think that the problem is something totally obvious, but I have reread the code sooo many times and just can't see the problem....

  • #4
    New to the CF scene
    Join Date
    Jun 2010
    Posts
    9
    Thanks
    1
    Thanked 1 Time in 1 Post
    Ohh, ic, that's just part of your signature...

  • #5
    New to the CF scene
    Join Date
    Jun 2010
    Posts
    9
    Thanks
    1
    Thanked 1 Time in 1 Post
    I thought it might have to do with the fact that I'm using .checked as part of the deal so I did this:

    Code:
    <script type="text/javascript">
    <!--
    $(document).ready(function() {
    		$('a.poptip').cluetip({cluetipClass: 'rounded', dropShadow: false, sticky: true, ajaxCache: false, arrows: true, activation: 'click',closePosition: 'top', closeText: '<img src="images/cross.png" alt="" />'});
    		$('img.definition').cluetip({splitTitle: '|'});
    		$('form').jqTransform({imgPath:'images/jqtransform/'});
    });
    
    window.onbeforeunload = function (){
    	var checkboxImg = new Image();
    	var cbl = reviews-chk-longer.checked;
    	var cbd = reviews-chk-discrete.checked;
    	var cbn = reviews-chk-natural.checked;
    	var cbt = reviews-chk-thicker.checked;
    	var cbp = reviews-chk-permanent.checked;
    	var cbs = reviews-chk-stamina.checked;
    	var cbh = reviews-chk-harder.checked;
    	var cbv = reviews-chk-vascularity.checked;
    	var cbb = reviews-chk-drive.checked;
    	var cbg = reviews-chk-guarantee.checked;
    	var cbc = reviews-chk-trials.checked;
    	var cba = reviews-chk-affordable.checked;
    	var checkboxImgUrl = "checkbox.php%3Flonger%3D"+cbl+"%26discrete%3D"+cbd+"%26natural%3D"+cbn+"%26thicker%3D"+cbt+"%26permanent%3D"+cbp+"%26stamina%3D"+cbs+"%26harder%3D"+cbh+"%26vascularity%3D"+cbv+"%26drive%3D"+cbb+"%26guarantee%3D"+cbg+"%26trials%3D"+cbc+"%26affordable%3D"+cba;
    	alert(checkboxImgUrl);
    	checkboxImg.src = checkboxImgUrl;
    }
    // -->	
    </script>
    But that still doesn't work!

  • #6
    New to the CF scene
    Join Date
    Jun 2010
    Posts
    9
    Thanks
    1
    Thanked 1 Time in 1 Post
    No one here knows? Please just help me out here, what am I doing wrong?

  • #7
    New Coder
    Join Date
    Feb 2010
    Posts
    44
    Thanks
    0
    Thanked 3 Times in 3 Posts
    One of your checkbox variables is probably spelled incorrectly or something and is returning null, which would make the entire function throw an exception and stop running.

    Remove all those checkbox variables and add one by one until you find the one that's offending. If having any single one of them fails and you know the variable name does point to something (ie you've done alert(reviews-chk-longer) to each one and gotten [object] (and none report 'null') and alert(reviews-chk-longer.checked) says true/false, then post again.

    This is how you debug without a debugger.

    gl


  •  

    Tags for this Thread

    Posting Permissions

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