This topic is locked

Add function to dropdown

3/29/2009 11:09:29 AM
ASPRunnerPro General questions
H
HilcrRWise author

I have a field on an edit page that has been setup as a drop down box, I also have a javascript function that I want to run when this drop down box is clicked. Where do I put the onlick=FunctName() event for this field? I am guessing it is in the custom option of the view as section of the fields properites, if this is correct how would the custom code need to be formatted.
Thanks

Sergey Kornilov admin 3/30/2009

Hi,
you can add the following at the end of the Edit page in Visual Editor (in HTML mode)

<script>

document.editform.fieldname_value.onchange = function(){
// add your code here
}

</script>
H
HilcrRWise author 4/1/2009

Can you pass arguments to the javascript code at the end of the html page?
I currently have this code listed at the end of the page which works greate for that one field:

<script type=text/javascript>

document.forms.editform.value_Comment.focus()

var x = document.editform.value_Comment

x.onkeyup=x.onfocus=x.onload=function()

{

if(document.forms.editform.value_Comment.value=="")

{

document.forms.editform.CommReq.style.visibility="visible"

}

else

{

document.forms.editform.CommReq.style.visibility="hidden"

}

}

</SCRIPT>


However I want to use the same code (except for the field references) for several fields.
If I could add a call to the code on each of the field references (ie: onClick="HideReq(document.forms.editform.value_Comment,document.forms.editform.CommR

eq") I could use something like this code at the start of the html:

<script type=text/javascript>

function HideReq(fieldref,imageref)

{

if(fieldref.value=="")

{

imageref.style.visibility="visible"

}

else

{

imageref.style.visibility="hidden"

}

}

</SCRIPT>


Can something similar be acomplished with code entered at the end of the html.
Thanks

J
Jane 4/2/2009

Hi,
you should edit generated include/commonfunctions.asp file to add javascript event (onclick for example) for each control on the page.

To avoid editing generated files JavaScript events (functions) are moved to the end of HTML file.