Jump to content

safari (iPhone) doesn't like my js


ginerjm

Recommended Posts

OK - here is a function I made (cut and pasted essentially) that works great on my laptop.  But on my iphone it gives me an error.  The error is vague - err.description reports as:  "undefined".

 

Here's the code, which as I said works great on ie.  Basically it grabs the selected item from a dropdown menu ("curdirs") and copies it (after a little cleanup) onto some other input fields.

 

<script type="text/javascript">
function displayResult()
{
var x=document.getElementById("curdirs").selectedIndex;
var y=document.getElementById("curdirs").options;

try
  {
var str = y[x].text;
var arstr = str.split(" ");
if (arstr.length >1)
	document.getElementById("mntstsy").checked = true;
else
	document.getElementById("mntstsn").checked = true;

  	str = arstr.shift();
  	document.getElementById("uid").value =str;
  	document.getElementById("dirstsy").checked = true;
  	document.getElementById("dirstsy").focus();
  }
catch(err)
  {
  txt="There was an error on this page.\n\n";
  txt+="Error description: " + err.description + "\n\n";
  txt+="Click OK to continue.\n\n";
  alert(txt);
  }
}

 

The code gets triggered by the onclick event.  I've tried onchange, onblur for the iphone becuase of some posts I read, but all that does is eliminate the error popup - it still doesn't do anything on the iphone.  Yes - I have read about the lack of support for the "select" tag on Safari, but I'm hoping someone has this a clue why this js doesn't work.  I certainly don't - I have all of 3 days of experience in it! :)

 

Link to comment
Share on other sites

The 'undefined' message is from err.description, because that itself is not defined. Try:

 

txt+="Error description: " + err.message + "\n\n";

 

Edit

 

Looks like you used a code snippet found on W3Schools - good advise would be not to use that site! Some idiot supposedly capable of teaching people to learn JavaScript has obviously checked the output in their TryIt editor thing, seen the "undefined" message and thought it was on about the undefined function in their example.

 

http://w3fools.com/

Link to comment
Share on other sites

Ha.. To be honest I started with w3schools too. Whenever you want to learn something new with JavaScript though, just search on Google. Read a couple of articles/tutorials from different sites to ensure you're not being taught bad things (this doesn't guarantee it obviously, but it's better), which is more likely to make it sink in hearing several different explanations anyway.

 

It's easy to spot someone who's learnt from W3Schools when they post a problem, because their code contains their crappy snippets.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.