This topic is locked

javascript

7/30/2009 5:49:50 PM
PHPRunner General questions
G
garethp authorDevClub member

Hi
I have always added javascript code in the visual editor by switching to html and adding the javascript at the bottom of the generated code.
However, on reset this is lost. Is there anywhere this can be added so that it will not be lost on reset. Is there anywhere like with events that this can be added and stored and not lost on reset.
Many thanks
Gareth

J
Jane 7/31/2009

Hi,
you can use custom event (Insert PHP code snippet option on the Visual Editor tab) for this purpose.

Here is a sample:

AddScript2Postload("alert('a');...");

G
garethp authorDevClub member 7/31/2009

Hi Jane
Thanks so much for responding. However, please forgive my stupidity (as you have many times!!!!). I have the followoing javascript (which in fariness to you, you told me)...

<script>

document.forms.editform.value_part.onchange=function()
document.forms.editform.value_net_value.disabled=true;

var vv = document.editform.value_unit_price;

var ww = document.editform.value_quantity;

vv.onchange = vv.onkeyup =ww.onchange = ww.onkeyup =function() {

var qty = document.editform.value_quantity.value;

var unit = document.editform.value_unit_price.value;

document.editform.value_net_value.value =parseFloat(qty)*parseFloat(unit);}
</script>


How would I put this in the

AddScript2Postload("alert('a');...");


Many thanks - I have wanted to achieve this for about a year now and never got round to it.

J
Jane 8/3/2009

Here is a sample:

AddScript2Postload("

document.forms.editform.value_net_value.disabled=true;

var vv = document.editform.value_unit_price;

var ww = document.editform.value_quantity;

vv.onchange = vv.onkeyup =ww.onchange = ww.onkeyup =function() {

var qty = document.editform.value_quantity.value;

var unit = document.editform.value_unit_price.value;

document.editform.value_net_value.value =parseFloat(qty)*parseFloat(unit);}");

G
garethp authorDevClub member 9/5/2009

HiJane
Thanks for your help. I have go this working by...
1)Click insert php code snippet on visual editor.

2)Type the following code in the box that appears....



AddScript2Postload("

document.forms.editform.value_net_value.disabled=true;

var vv = document.editform.value_unit_price;

var ww = document.editform.value_quantity;

vv.onchange = vv.onkeyup =ww.onchange = ww.onkeyup =function() {

var qty = document.editform.value_quantity.value;

var unit = document.editform.value_unit_price.value;

document.editform.value_net_value.value =parseFloat(qty)*parseFloat(unit);}");


This works great and I can see the code appear on the events page under a new event called por_detail_snippet1 with the above code in it.
I also see that {$event por_details_Snippet1} is added to the code on the visual editor page.
This is great until you need to reset and then the {$event por_details_Snippet1} code is removed from the visual editor page and the code is then therefore ignored.
How can this code be stored so resets do not stop this working. Is this possible?
Many thanks for the great support.