473,320 Members | 1,990 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Update function variable on same page

I have a snippet of a function below I fire up in the body tag of my
webpage to show a hidden layer and do some stuff when any link with
the name "showlink" is clicked.

In the displayed layer there is some html and more javascript. How
would I update the value of "str" with "node_id" each time a link is
clicked? I can't figure it out...

Many thanks,

Chris
// function in body tag
function showStuff(evt,txt){
var node = (evt.target) ? evt.target : ((evt.srcElement) ?
evt.srcElement : null );

if (node.getAttribute("NAME") == "showlink") {
node_id = node.getAttribute("ID");
var cfmBox = document.getElementById(frmBox);

var cfmData = document.getElementById("cfmDataAsset");
cfmData.setAttribute('value', node_id);
}
}
-----------------------------------------------------------------------------------------------------------------------
// script in body, hidden layer
<script type="text/javascript">
myFunction(str);
</script>
Oct 16 '08 #1
1 2201
On Oct 17, 8:42 am, Chris <matchett...@googlemail.comwrote:
I have a snippet of a function below I fire up in the body tag of my
webpage to show a hidden layer and do some stuff when any link with
the name "showlink" is clicked.

In the displayed layer there is some html and more javascript. How
would I update the value of "str" with "node_id" each time a link is
clicked? I can't figure it out...
The simple way is to declare a global variable and update its value
when required. You can also use a closure to hold the variable so
that it becomes private, that way you can control access to read and
write its value.

If you have many such variables, you can create a single global object
that has them as properties. That makes management a lot easier and
you can create get/set methods of the same object to control access to
their values. See:

<URL: http://javascript.crockford.com/private.html >

Many thanks,

Chris

// function in body tag
I guess you mean in a script element in the body element.
function showStuff(evt,txt){
var node = (evt.target) ? evt.target : ((evt.srcElement) ?
evt.srcElement : null );
The following should be sufficient:

var node = evt.target || evt.srcElement;
>
if (node.getAttribute("NAME") == "showlink") {
If node hasn’t been set to an object that supports the getAttribute
method, you’ll get an error. The getAttribute method is a bit buggy
so best not to use it if you don’t have to - access the property
directly. Also, check node is not undefined before trying to read its
attributes:

if (node && node.name == ‘showlink’)

node_id = node.getAttribute("ID");

You can access the id property of node directly as node.id, there is
no need for getAttribute.
var cfmBox = document.getElementById(frmBox);

var cfmData = document.getElementById("cfmDataAsset");
cfmData.setAttribute('value', node_id);}
Again, ditch getAttribute, access properties directly:

if (cfmData) cfmData.value = node.id;
}

--
Rob
Oct 17 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Penn Markham | last post by:
Hello all, I am writing a script where I need to use the system() function to call htpasswd. I can do this just fine on the command line...works great (see attached file, test.php). When my...
0
by: Sue Adams | last post by:
I actually have two issues/questions: I have an autonumber field in an access db table that I grab and later use to update a record in another table withing the same db. The code I use to get...
4
by: shank | last post by:
Visually, the page will look somewhat like a spreadsheet. It could have hundreds of records (rows) displayed. I want to enable the user to edit any one or any number of records and any fields, then...
4
by: gooday | last post by:
Table test2 has multiple amounts for each account, I would like to sum the amounts for the same account and use the result to update the variable 'tot_amount' in table test1. But SQL does not allow...
2
by: laredotornado | last post by:
Hello, I am looking for a cross-browser way (Firefox 1+, IE 5.5+) to have my Javascript function execute from the BODY's "onload" method, but if there is already an onload method defined, I would...
0
by: darrel | last post by:
I have a user control that sets a public shared variable that I then access from the parent page: projectclass.controlclass.thevariable the problem I'm finding is that if I have the variable...
28
by: Larax | last post by:
Best explanation of my question will be an example, look below at this simple function: function SetEventHandler(element) { // some operations on element element.onclick = function(event) {
1
tolkienarda
by: tolkienarda | last post by:
i need to update a database table using variables in unusual places here are the update statements mysql_query("UPDATE 'grades' SET '$class' = '$grade' WHERE student='$student'");...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.