473,775 Members | 2,621 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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,t xt){
var node = (evt.target) ? evt.target : ((evt.srcElemen t) ?
evt.srcElement : null );

if (node.getAttrib ute("NAME") == "showlink") {
node_id = node.getAttribu te("ID");
var cfmBox = document.getEle mentById(frmBox );

var cfmData = document.getEle mentById("cfmDa taAsset");
cfmData.setAttr ibute('value', node_id);
}
}
-----------------------------------------------------------------------------------------------------------------------
// script in body, hidden layer
<script type="text/javascript">
myFunction(str) ;
</script>
Oct 16 '08 #1
1 2222
On Oct 17, 8:42 am, Chris <matchett...@go oglemail.comwro te:
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,t xt){
var node = (evt.target) ? evt.target : ((evt.srcElemen t) ?
evt.srcElement : null );
The following should be sufficient:

var node = evt.target || evt.srcElement;
>
if (node.getAttrib ute("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.getAttribu te("ID");

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

var cfmData = document.getEle mentById("cfmDa taAsset");
cfmData.setAttr ibute('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
4964
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 webserver runs that part of the script (see attached file, snippet.php), though, it doesn't go through. I don't get an error message or anything...it just returns a "1" (whereas it should return a "0") as far as I can tell. I have read the PHP...
0
2783
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 it from the db table is: ''Retrieve the Registration Identification Number strRegisterID = Rs("Register_ID") Prior to testing my code and actually updating the db, I''m trying to write it to the page to make sure their isn''t a loop or massive...
4
6139
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 click a save button to UPDATE the SQL table. I'd like to use stored procedures if possible. How is this done? Where do I start? thanks
4
79487
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 me to use sum function in update. Is there any other way to do this? Thanks. update test1 set tot_amount=sum(b.amount) from test1 as a join test2 as b on a.acc_no=b.acc_no
2
7678
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 like mine to run immediately after it. So in the code below, what JS would i need to add to my "myfile.inc" page so that I could guarantee this behavior? <!-- main page --> <html> <head> <script type="text/javascript">
0
973
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 set in the user control within the Page_Load function, it is 'one' page reload behind the parent page. In otherwords, it appears that the parent page grabs the variable, THEN the control's function is executed to update the variable. The quick fix...
28
4336
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
1999
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'"); mysql_query("UPDATE 'assignments' SET '$class' = '$grade' WHERE student='$student'"); mysql_query("UPDATE 'comments' SET '$class' = '$grade' WHERE student='$student'"); now i was just showed by ron how to recive post stuff and that is where the variables come...
0
9454
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10268
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8939
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7464
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6718
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5486
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4017
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3611
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2853
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.