Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations dencom on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Javascript not returning value into textbox in different brower

Status
Not open for further replies.

hpadwal

Programmer
Feb 6, 2006
57
GB
I have a Javascript function that returns a value and places it in a read only textbox. This isnt working on safari, the text box remains empty, The functions works perfectly in Firefox and IE!

Here is some of the code.

the following returns the result.

Code:
	var total
	var discount
	
	total = premsum + packsum
	discount = premsum + totalpacksum
	
	thisform.premoutput.value = premsum;
	thisform.discountsum.value = total.toFixed(2);
	thisform.totalsum.value = discount.toFixed(2);

Can you help?

_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/

- Doh

 
oops, here is the text box the values go into

Code:
<input type="text" name="discountsum" size="4" readonly="true" class="altTextField"  />
					

<input type="text" name="totalsum" size="4" readonly="true" class="altTextField" />

_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/

- Doh

 
Not familiar with Safari but inside your function do an alert with the values of total and discount prior to writing them to the fields.

Also, in the code above you have not set a value for presum, packsum or totalpacksum so there is no way it can calculate.

If any of your values are treated as strings in the javascript and you try to use toFixed on them you will end up with an empty value as well.

Stamp out, eliminate and abolish redundancy!
 
As well as the two previous excellent suggestions, have you stopped to think what you're actually asking?

You are trying to write a value to a read-only field. Maybe Safari stops this? After all - it *is* a read-only field, so why should you be able to write to it?

Consider not using a field at all.

Dan



[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
The JS function is called when the user clicks checkbox. The functions calucated the price of certain pacages and offers.

Code:
<form name="stage1" method="POST" action="default2.asp?id=<%=id%>">

Code:
<input type="checkbox" name="package4" value="1" onclick="package_select(4);calculate(stage1);" style="cursor:hand" />

All presum, packsum or totalpacksum have been defined and set values, i just havent included it as the script is long, and works correctly in all browers EXCEPT safari.

The "read only" textbox is so users cant change the figures, If i remove the Read only tag the java script still doesnt work in SAFARI.

Basically i need to know if it there is anything in my javascript that is not leeting it work in SAFARI.

If you want the whole function i can post it, its just that i thought you may not need it.

Thank you






_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/

- Doh

 
Did you try the alert to make certain you were getting the values in Safari?
This will tell you if the problem is the retrieving of the values or the writing of the values and narrow your search.


Stamp out, eliminate and abolish redundancy!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top