quiettech Posted April 11, 2008 Share Posted April 11, 2008 Hello all, I'm having trouble defining how I should complement event handlers in a situation where javascript is either disabled or not supported. I have a simple event handler: <a href='#' onclick="doPrice('<?php echo $_SESSION['currency'] ?>')">Change to <?php echo $_SESSION['currency'] == 'EUR' ? 'Pounds.' : 'Euros.'; ?></a> All doPrice() does is set a cookie and alter the DOM to display prices in the correct currency. I want server side scripting to do this for me in case javascript is not available. The problem is not how to do it with PHP. The problem is how to correctly present a noscript tag to replace the above. How do you replace event handlers in no script situations? Quote Link to comment Share on other sites More sharing options...
Psycho Posted April 11, 2008 Share Posted April 11, 2008 Well, a NOSCRIPT tag would not prevent the above link from showing - it would just not work for users that don't have JS enabled. IMHO, the best process is to first build the page with no JavaScript. Then once it is complete find where you can add JS to make it more user-friendly. In this case, though I think there is an easy solution. Add an actual link to the href property. I would suggest linking back to the current page, but adding a parameter on the URL for the currency to be displayed (You would need to modify the page to accept that parameter and display the appropriate currency on reload). Then that link will work for users that do not have JS enabled. But, you don't want that link to refresh the page for users with JS enabled. So, just add a "return false;" to the onclick property and that will prevent the link from actually firing for JS users. <?php $changeCurrency = ($_SESSION['currency']=='EUR') ? 'Pounds.' : 'Euros.'; ?> <a href="<?php echo $_SERVER[php_SELF]?currency=$changeCurrency; ?>" onclick="doPrice('<?php echo $_SESSION['currency'] ?>');return false;"> Change to <?php echo $changeCurrency; ?> </a> Quote Link to comment Share on other sites More sharing options...
quiettech Posted April 11, 2008 Author Share Posted April 11, 2008 Thanks mj, Another thing that occurred to me after posting (it's always after posting, bleh!) is that I could document.write the whole anchor tag. On that case a <noscript> tag would become a viable alternative. Anyways, either way it's solved. Thanks again. Quote Link to comment Share on other sites More sharing options...
Psycho Posted April 11, 2008 Share Posted April 11, 2008 ... I could document.write the whole anchor tag. On that case a <noscript> tag would become a viable alternative. Maybe, but the process I identified above is the preferred approach. Quote Link to comment Share on other sites More sharing options...
quiettech Posted April 11, 2008 Author Share Posted April 11, 2008 I agree it is. No doubt. Quote Link to comment 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.