...

View Full Version : Combining String in Javascript



serjsagan
06-11-2010, 08:15 PM
I am throughly confused....why does this seemingly simple deal not work?



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



<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

tomws
06-11-2010, 09:35 PM
***** pill spammer, eh? I think I'll let this one pass.

serjsagan
06-11-2010, 11:08 PM
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....

serjsagan
06-11-2010, 11:20 PM
Ohh, ic, that's just part of your signature...

serjsagan
06-11-2010, 11:55 PM
I thought it might have to do with the fact that I'm using .checked as part of the deal so I did this:


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

serjsagan
06-12-2010, 06:18 AM
No one here knows? Please just help me out here, what am I doing wrong?

Skychan
06-13-2010, 05:38 AM
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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum