javascript working on all browsers except safari

Discussion in 'JavaScript' started by macaela, Oct 13, 2011.

  1. #1
    Hi i have this script which has a submit button what the javascript does is if user doesnt select an option from the drop down menu an alert pops up saying (select tv option)

    The problem is it works fine all al browsers except on safari if the user select one option and (click here to view) the new page opens on a new new tab now if you try to select a new option again and click the the submit button (click here to view) it doesnt work on second selection it the issue seems to be only on safari all other browsers work fine please help
    my site is this one http://www.estateagentsonfilm.co.uk/builders.php the drop down is the (select tv agent drop down ) then click here to view if you try select and click twice doesnt work only on safari
    this my javascript
    <script type="text/javascript">
    	function checkAgent() {
    		if (document.getElementById('agent_select').value=='none') {
    			alert('Select Web TV');
    			return false;
    		}
    		return true;
    	}
    </script>
    Code (markup):
    the form that calls the script
    form id="agents" action="agents_jump.php" onsubmit="return checkAgent();" method="post"  target="_blank" name="agents" style="margin:0;">
    PHP:
     
    macaela, Oct 13, 2011 IP
  2. macaela

    macaela Active Member

    Messages:
    181
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    51
    #2
    Hi i thsi is a simple example of my issue if you test this script on safari by selecting the from the drop down twice you'll notice that second time it doesnt work but if you test on a differnt browser it works any help would be much appreciated
    <html>
    <head>
    <script type="text/javascript">
       function checkAgent() {
          if (document.getElementById('agent_select').value=='none') {
             alert('Select Web TV');
             return false;
          }
          return true;
       }
    </script>
    </head>
    <body>
    
    <form id="agents" action="agents_jump.php" onsubmit="return checkAgent();" method="post"  target="_blank" name="agents" style="margin:0;">
    <select name="agents" id="agent_select" size="1" style="width:160px; font-size:13px;">>
      <option value="none">Volvo</option>
      <option>Saab</option>
      <option>Mercedes</option>
      <option>Audi</option>
    </select>
    
    <input class="view_agents" id="tvoption" type="image" src="images/viewagents.gif" alt="TV OPTION" name="tvoption"  border="0"   onclick="jwplayer().stop();">
    </form>   
    </body>
    </html> 
    PHP:
     
    macaela, Oct 13, 2011 IP
  3. JohnnySchultz

    JohnnySchultz Peon

    Messages:
    277
    Likes Received:
    4
    Best Answers:
    7
    Trophy Points:
    0
    #3
    might be a Safari bug, what i can suggest to you is to reload the page on submit maybe after a few seconds..

    
    
    <script type="text/javascript">
       function checkAgent() {
          if (document.getElementById('agent_select').value=='none') {
             alert('Select Web TV');
             return false;
          }
          setTimeout(function(){ location.reload(); },2000); // page will reload after 2 seconds
          return true;
       }
    </script>
    
    HTML:
     
    JohnnySchultz, Oct 14, 2011 IP
  4. wspeedupw

    wspeedupw Peon

    Messages:
    106
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    oh,it looks so difficulty
     
    wspeedupw, Oct 14, 2011 IP
  5. macaela

    macaela Active Member

    Messages:
    181
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    51
    #5
    Hi the this setTimeout(function(){ location.reload();
    just one problem before i used to have when submit (onclick="jwplayer().stop();)
    now i tried to implement the jwplayer sto function next to the set timeout but doesnt work.
    like this
    setTimeout(function(){ location.reload(); jwplayer().stop(); },2000); // page will reload after 2 seconds
    		return true;
    	}
    Code (markup):
    have i got the line wrong or that is not realistic way to do it?
     
    macaela, Oct 14, 2011 IP
  6. Rukbat

    Rukbat Well-Known Member

    Messages:
    2,908
    Likes Received:
    37
    Best Answers:
    51
    Trophy Points:
    125
    #6
    
    setTimeout(function(){ [COLOR=#ff0000]location.reload()[/COLOR]; [COLOR=#008000]jwplayer().stop()[/COLOR]; },2000);
    
    Code (markup):
    Once the red part executes, the green part is no longer in memory, so it doesn't do anything.

    
    setTimeout(function(){jwplayer().stop(); location.reload();},2000);
    
    Code (markup):
    may do it.
     
    Rukbat, Oct 14, 2011 IP
    jazzcho likes this.