stephenT Posted April 22, 2012 Share Posted April 22, 2012 Can anyone please advise what i am missing in my code? I want the displayed price to show as $k when under $999,999 and $mil when over $1 million. Example: $990000 should display as $990k (which it does) BUT $1,100,000 should display as $1.1mil, and the same with values under $1mil should show as $k not $0.9mil. Hope that makes sense. $(function() { $( "#slider-range" ).slider({ range: true, min: 0, max: 2000000, values: [ 0, 2000000 ], step: 10000, slide: function( event, ui ) { if("HousePrice_max" < 1000000) $( "#HousePrice" ).val( "$" + ui.values[ 0 ]/1000 + "k - $" + ui.values[ 1 ]/1000 + "k" ); else $( "#HousePrice" ).val( "$" + ui.values[ 0 ]/1000 + "k - $" + ui.values[ 1 ]/1000000 + "mil" ); } Quote Link to comment https://forums.phpfreaks.com/topic/261410-if-else-not-working/ Share on other sites More sharing options...
trq Posted April 22, 2012 Share Posted April 22, 2012 I haven't even read your post, mostly because I couldn't be bothered considering you couldn't be bothered popsting it within the correct board. This however: if("HousePrice_max" < 1000000) makes little sense. How exactly do you expect the string "HousePrice_max" to be less than the int 1000000 Ever heard the expression "like comparing apples and oranges" ? Quote Link to comment https://forums.phpfreaks.com/topic/261410-if-else-not-working/#findComment-1339528 Share on other sites More sharing options...
stephenT Posted April 22, 2012 Author Share Posted April 22, 2012 WOW. I'm new to php, this is my first post, it might be my last as i didn't expect this type of hostility on here. I was under the impression this forum was to help people with php. Quote Link to comment https://forums.phpfreaks.com/topic/261410-if-else-not-working/#findComment-1339536 Share on other sites More sharing options...
haku Posted April 22, 2012 Share Posted April 22, 2012 It is, but you posted a javascript question (I'm assuming in the PHP area). Anyways, to elaborate on the last poster's comment: if("HousePrice_max" < 1000000) You are comparing a string (text) of "HousePrice_max" to a number. What are you trying to compare to? Quote Link to comment https://forums.phpfreaks.com/topic/261410-if-else-not-working/#findComment-1339538 Share on other sites More sharing options...
trq Posted April 22, 2012 Share Posted April 22, 2012 I'm new to php, this is my first post, it might be my last as i didn't expect this type of hostility on here. I was under the impression this forum was to help people with php. The PHP Help board *is* for help with PHP questions. Unfortunately, your code is not PHP. All i have done is move your question to the appropriate board and ask you a question. Quote Link to comment https://forums.phpfreaks.com/topic/261410-if-else-not-working/#findComment-1339540 Share on other sites More sharing options...
stephenT Posted April 22, 2012 Author Share Posted April 22, 2012 Ok i have just realized it was a javascript function i was trying to modify. Quote Link to comment https://forums.phpfreaks.com/topic/261410-if-else-not-working/#findComment-1339542 Share on other sites More sharing options...
stephenT Posted April 22, 2012 Author Share Posted April 22, 2012 You are comparing a string (text) of "HousePrice_max" to a number. What are you trying to compare to? The function is attached to a jQuery slider with min and max values of 0 & 2000000 and the prices are stored in MySQL database Quote Link to comment https://forums.phpfreaks.com/topic/261410-if-else-not-working/#findComment-1339545 Share on other sites More sharing options...
haku Posted April 22, 2012 Share Posted April 22, 2012 So you are trying to check against the selected value? I'm not familiar with the plugin, but just looking at your code, I'd assume it's something like this: if(ui.values[ 0 ] < 1000000) Quote Link to comment https://forums.phpfreaks.com/topic/261410-if-else-not-working/#findComment-1339548 Share on other sites More sharing options...
stephenT Posted April 22, 2012 Author Share Posted April 22, 2012 That's correct. I have it working however it is showing as $0.99mil when the slider goes below $1mil, i want it to display as $990k NOT $0.99mil. The same with the left slider, it displays as $990k for example but does not change to $mil when it goes over $1mil, instead displays as $1100k for example instead of $1.1mil Quote Link to comment https://forums.phpfreaks.com/topic/261410-if-else-not-working/#findComment-1339549 Share on other sites More sharing options...
stephenT Posted April 22, 2012 Author Share Posted April 22, 2012 var HousePrice_min = $( "#slider-range" ).slider( "values", 0 ); var HousePrice_max = $( "#slider-range" ).slider( "values", 1 ); Quote Link to comment https://forums.phpfreaks.com/topic/261410-if-else-not-working/#findComment-1339551 Share on other sites More sharing options...
stephenT Posted April 22, 2012 Author Share Posted April 22, 2012 Don't worry, just worked it out myself. Quote Link to comment https://forums.phpfreaks.com/topic/261410-if-else-not-working/#findComment-1339555 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.