sheridan Posted October 21, 2013 Share Posted October 21, 2013 (edited) I am trying to finalise a co-creation website that swaps image when certain radio buttons are selected. It works in Firefox.. can anyone tell me why it is not working in Safari? http://www.designpartners.co.uk/Product/SmartPhone_Skin/ The part that I feel does not connect is as below: } var sel = document.getElementById("mainimg"); var s = grps+""; while (s.length < 5) s = "0" + s; sel.src = "http://www.designpartners.co.uk/resources/iPhone-skins/skin-options/iPhone_Skins_Art_Case"+s+".png"; } function addmodelid() { var textbox = document.getElementById("item_number"); var mainimg = document.getElementById("mainimg"); var s = mainimg.src textbox.value = s.substring(71); return true; } </script> <div id="columns"> <div class="right column"> <p><img title="Fudged Skins" id="mainimg" alt="mainimg" src="http://www.designpartners.co.uk/resources/iPhone-skins/skin-options/iPhone_Skins_Art_Case02000.png" height="480" width="380" border="0" onsubmit="return addmodelid()"(mainimg)> Edited October 22, 2013 by sheridan Link to comment Share on other sites More sharing options...
justsomeguy Posted October 21, 2013 Share Posted October 21, 2013 What's that "(mainimg)" doing inside the img tag? It takes several seconds to download each image after clicking on the button, are you just not giving it enough time in Safari? I don't have Safari installed but it uses the same engine as Chrome so I'm testing it in Chrome. Otherwise, open the error console in Safari to check for Javascript error messages. Link to comment Share on other sites More sharing options...
Hadien Posted October 21, 2013 Share Posted October 21, 2013 No it definitely not working on iPadI played with src in w3schools tryit pages and was able to get it to work fine, so it's not a support issue.Try alerting sel.src immediately after setting it. See if safari is messing with it behind your back. Still doesn't explain why the image isn't breaking on my end though. I mean if the URL is invalid safari should show the broken img icon. Other possibilities could be a caching problem ( safari might think it hasn't actually changed even if src did. add on a ?rand=rand() at the end or something similar) or lack of preventDefault ( unsure if that would matter here). It might even be that (mainimg) you have stuck in the attributes and safari could fail to parse it. 1 Link to comment Share on other sites More sharing options...
dsonesuk Posted October 21, 2013 Share Posted October 21, 2013 Is onchange event correctly used? I thought is was for form elements such as select and input elements radio ( even though i think there a problem in safari using onchange, where onclick should be used instead) and checkbox, not a td element. 1 Link to comment Share on other sites More sharing options...
sheridan Posted October 22, 2013 Author Share Posted October 22, 2013 (edited) Simples:The sel.src function was not changing the image file name in Safari - which was evident in the paypal post... so I knew it was not a cache problem... ! But I didnt know that Safari doesnt like onchange - it does like onclick though!!!! Sacred is true. Thanks! Edited October 22, 2013 by sheridan Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now