Advertise here




Advertise here

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Google Sign In with OpenID
Please do not post the same thing multiple times. The board software automatically flags certain posts as needing moderator attention. This happens the most often for new users. I'm pretty sure this is made clear at the time you attempt to post. Posting the same thing over and over again just makes that many more posts the moderators have to weed through later. This makes us sad. Don't make us sad. If your post/thread doesn't appear, just wait a while. Don't post it again. If it hasn't shown up by the next day, then you can try again. I normally go through posts in the mornings, and try to check a few times throughout the day, but I'm not here 24/7. There will typically be a significant delay before posts are approved. Just be patient.

Passing date value from objective C to Javascript

ashwinr87ashwinr87 Posts: 115Registered Users
I am trying to pass a array of date values from Objective C to Javascript. I tried to pass it this way -
NSArray *array = [NSArray arrayWithObjects:@\"01-03\",@\"01-05\",@\"01-07\",@\"01-09\",@\"01-11\", nil];
self.dateString = [array componentsJoinedByString:@\",\"];
[wtWebView stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@\"methodName([%@])\", dateString]];


In my Javascript -
<script>
function methodName(val,val1)
{
alert(val1);
}
</script>


However, what happens here is that the value get displayed as -2, -4, -6, -8, -10 . It literally does a subtraction operation on the values.

Would someone be able to help me out with how I can get this working?
Post edited by ashwinr87 on

Replies

  • ShawnArneyShawnArney Posts: 7New Users
    I'm guessing the javascript is interpreting this as a number... on the alert call...

    i.e. this is what the call looks like to alert:

    alert(01-03)

    So, it's going to interpret that as a number.

    So, you'll need to figure out how to get the javascript to interpret this as a string.

    Maybe adding the ' ' as I did below will work??

    i.e.
    [wtWebView stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"methodName(['%@'])", dateString]];

    Here is a javascript emulator that may be useful for debugging

    Tryit Editor v1.5
  • ashwinr87ashwinr87 Posts: 115Registered Users
    Thanks for the reply..
    this is what I did to get it working -
    NSArray *array = [NSArray arrayWithObjects:@\"01-03\",@\"01-05\",@\"01-07\",@\"01-09\",@\"01-11\", nil];

    self.dateString = [array componentsJoinedByString:@\"','\"];

    [wtWebView stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@\"methodName(['%@'])\", dateString]];
    ShawnArney;404199 said:
    I'm guessing the javascript is interpreting this as a number... on the alert call...

    i.e. this is what the call looks like to alert:

    alert(01-03)

    So, it's going to interpret that as a number.

    So, you'll need to figure out how to get the javascript to interpret this as a string.

    Maybe adding the ' ' as I did below will work??

    i.e.
    [wtWebView stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"methodName(['%@'])", dateString]];

    Here is a javascript emulator that may be useful for debugging

    Tryit Editor v1.5
Sign In or Register to comment.