Link to home
Start Free TrialLog in
Avatar of TeamLink
TeamLink

asked on

Setting Form Values by Javascript in Safari on iPhone Isn't Working

We have a web based application.

As such, this is accessable on an iPhone through it's safari browser. However, there are some small parts of the system which don't work...

On the page, when clicking certain buttons, we set a hidden field which is then used to determine what happens once the form is submitted. This field is called "action" and is defined on the form as such...

<input type="hidden" name="action">

When we submit the form, we do the following before submission on  a button on the form.

onclick="this.form.action.value='Save';return formValidate()"

The "return formValidate" works perfectly, but the previous statement that sets the field value does not - or at least if it does, the value is lost when the form is submitted.

Without it, our web app doesn't know what to do!

This works on all browsers we have tested with - IE6/IE7/FF/Opera - even Safari 3 Beta on Windows, but just will not work on the iPhone. I have tried various different ways of setting that field value, but with no success.

So, does anyone have any ideas?

Thanks,

Phil
Avatar of Stacy Spear
Stacy Spear
Flag of United States of America image

Did you try the onchange event? Just wondering if it can be called a click since it is a touch screen.
Avatar of TeamLink
TeamLink

ASKER

thanks, but it's not the onclick event thats the problem - the second part of the code that is on the onclick event above - the "doValidate()" works fine, so it can handle the onclick, it just seems that its the setting of the form value that isn't working.

Also, to give a bit more information - if I hard-code the action into the form... i.e...

<input type="hidden" name="action" value="Save">

...it does remember the value, so it's not losing the value on submit, it's just not being set by the onclick.

thanks,

Phil
Since it is calling the function, maybe instead of setting the value their, call a function that does the setting to see if that changes it. The only way I can imagine that not working is if the object reference isn't being passed properly.
Hi, thanks darkstar, but I've already tried that - and nu luck I'm afraid!

Phil
Is there any innerhtml going on in the form, ie you are adding some form items from javascript? I had issues with Safari and IE not liking that sometimes.
No, theres nothing of that nature that should affect this form.
I'm lost then. You are revalidating once it hits the server right? Choose the action there, you can't rely on the fact that javascript is enabled, although it is on 97% of the browsers that hit our sites.
Sorry, I am not sure what you mean by "revalidating once it hits the server".

I don't think javascript is the problem as other javascript in the system works OK on the phones browser.
ASKER CERTIFIED SOLUTION
Avatar of Stacy Spear
Stacy Spear
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Forced accept.

Computer101
EE Admin