[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.javascript

Update Java script variables dynamically

techie24by7

9/1/2015 12:45:00 PM

Hello All,

How you doing.

I have a requirement to change SVG drawn image dynamically based on user given inputs from UI screen. The inputs are rows and columns.

below is html code
------------------

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<title>Self Organizing Maps</title>

<script type="text/javascript" src="http://d3js.org/d3.v3.js"></...
<script type="text/javascript" src="http://d3js.org/d3.hexbin.v0.min.js"></...
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.3/jquery.js"></...


<script>


function handleIt(){

r = document.getElementById('r').value;
c = document.getElementById('c').value;
p = document.getElementById('p').value;

alert(r+''+c+''+p);

MapColumns=c;
MapRows=r;

}


</script>

</head>
<body>
<div style="width:100%;">
<div id="header">
<h1>Map</h1>
</div>
<div id="nav">

<form action="javascript:handleIt()">
Row#<br>
<input type="text" id="r" name="row" value="12" size="4" maxlength="4">
<br>
Column#<br>
<input type="text" id="c" name="column" value="20" size="4" maxlength="4">
<br>
Size of Cell<br>
<input type="text" id="p" name="cell" value="50" size="4" maxlength="4"> px
<br>
<input type="**submit**" value="GO">
</form>
</div>
<div style="float:right; width:90%;">
<div id="chart" style="overflow:auto; "></div>
<script type="text/javascript" src="script.js"></script>
</div>
</div>
</body>
</html>


In above index.html i have external java script being referred.

<script type="text/javascript" src="script.js"></script>
script.js has below variable.

var MapColumns = 20, MapRows = 12;

upon click of submit button in index.hmtl code, i want capture the values of r,c and update MapColumns, MapRows values in java script (script.js) and reload the page , how can i do that.

6 Answers

Wexford

3/31/2010 6:45:00 PM

0

On Mar 31, 2:14 pm, "Violent Chicago Obamathug"
<Obamat...@WhiteHouse.gov> wrote:
> "Ron" <roneal1...@att.net> wrote in message
>
> news:11b804aa-1f66-4d2b-8c13-5be877250709@l36g2000yqb.googlegroups.com...
>
> > On Mar 31, 8:33 am, "Violent Chicago Obamathug"
> > <Obamat...@WhiteHouse.gov> wrote:
> >> N.Y. Times columnist: Death panels will save 'a lot of money'
> >> Paul Krugman tells 'Roundtable' economists agree it's 'going to be major'
> > (SNIPPED)
> > .
> > .
> > Would you please identify the portion(s) of the Health Care bill that
> > provides for Death Panels?
>
> > RO
>
> >==========================
>
> Instead of trying find the hidden exclusions in the bill, please cite for us
> on what page does the Obamabill say that everyone gets anything and
> everything they need for treatment no matter what the cost to taxpayers via
> Obamacare.
> Even Obama says  just give Granny the  pain pill instead of treatment.
>
> Jane asks the President if her 100 year old mother (now 105) would have
> gotten a pacemaker under his plan. Well now that's a tough one ... that
> costs a lot and maybe we will have to say, just take a pill. Priceless.
>
> http://www.youtube.com/watch?v=U...

Actually the whole blow for a pacemaker is about $4,000 -- $8,000,
including device, installation and activation. It's at the higher end
if you have no insurance. In other words, it's not that expensive. A
heart transplant, on the other hand, runs to $150K or more and the
chances of granny surviving one are nil.

All you do with that adolescent question is put the bar so high it is
virtually unachievable. Krugman states flatly denying care that would
prove expensive but ineffective would save money. How does that
describe a death panel? I'd take my chances any day with a board of
people who did not work for the insurance companies rather than trust
the corporation to make live or die decisions based on cost and
profitability.

Ron

3/31/2010 9:20:00 PM

0

On Mar 31, 1:14 pm, "Violent Chicago Obamathug"
<Obamat...@WhiteHouse.gov> wrote:
> "Ron" <roneal1...@att.net> wrote in message
>
> news:11b804aa-1f66-4d2b-8c13-5be877250709@l36g2000yqb.googlegroups.com...
>
> > On Mar 31, 8:33 am, "Violent Chicago Obamathug"
> > <Obamat...@WhiteHouse.gov> wrote:
> >> N.Y. Times columnist: Death panels will save 'a lot of money'
> >> Paul Krugman tells 'Roundtable' economists agree it's 'going to be major'
> > (SNIPPED)
> > .
> > .
> > Would you please identify the portion(s) of the Health Care bill that
> > provides for Death Panels?
>
> > RO
>
> >==========================
>
> Instead of trying find the hidden exclusions in the bill, please cite for us
> on what page does the Obamabill say that everyone gets anything and
> everything they need for treatment no matter what the cost to taxpayers via
> Obamacare.
> Even Obama says  just give Granny the  pain pill instead of treatment.
>
> Jane asks the President if her 100 year old mother (now 105) would have
> gotten a pacemaker under his plan. Well now that's a tough one ... that
> costs a lot and maybe we will have to say, just take a pill. Priceless.
>
> http://www.youtube.com/watch?v=U...
>
> :  Obama  healthcare  Jane Sturm  take a pill  because treatment may be too
> expensive.
.
.
(SIGH)....Where.....but WHERE in the bill is a Death Panel designated?

Jeezus H. KoolAid !

RO

Straw Man

4/1/2010 11:01:00 AM

0

On Wed, 31 Mar 2010 14:14:08 -0400, "Violent Chicago Obamathug"
<Obamathug@WhiteHouse.gov> wrote:

>
>
>"Ron" <roneal1554@att.net> wrote in message
>news:11b804aa-1f66-4d2b-8c13-5be877250709@l36g2000yqb.googlegroups.com...
>> On Mar 31, 8:33 am, "Violent Chicago Obamathug"
>> <Obamat...@WhiteHouse.gov> wrote:
>>> N.Y. Times columnist: Death panels will save 'a lot of money'
>>> Paul Krugman tells 'Roundtable' economists agree it's 'going to be major'
>> (SNIPPED)
>> .
>> .
>> Would you please identify the portion(s) of the Health Care bill that
>> provides for Death Panels?
>>
>> RO
>>
>>==========================
>
>Instead of trying find the hidden exclusions in the bill, please cite for us
>on what page does the Obamabill say that everyone gets anything and
>everything they need for treatment no matter what the cost to taxpayers via
>Obamacare.
>Even Obama says just give Granny the pain pill instead of treatment.
>
>
>Jane asks the President if her 100 year old mother (now 105) would have
>gotten a pacemaker under his plan. Well now that's a tough one ... that
>costs a lot and maybe we will have to say, just take a pill. Priceless.
>
>http://www.youtube.com/watch?v=U...
>
>: Obama healthcare Jane Sturm take a pill because treatment may be too
>expensive.

what kind of idiot do you have to be to think that Obama would have
given a pill to this woman when he specifically stated he was
referring to people who _could not_ be helped by technology?

he specifically excluded this woman's mother from the group he was
referring to, so you really are a bona fide moron if you think he was
talking about the mother.

just another example of how right wing hatred of Obama takes
precedence over facts and reality. how sad. you will never win another
election.

Now answer the question-

Would you please identify the portion(s) of the Health Care bill that
provides for Death Panels?

Evertjan.

9/1/2015 2:01:00 PM

0

techie24by7@gmail.com wrote on 01 Sep 2015 in comp.lang.javascript:
> In above index.html i have external java script being referred.

Impossible.

There is no "Java script", as "Java" has no script version.

There is "Javascript", and that is not a script version of "Java".

There even is someone who is convinced that there is no "Javascript".

> <script type="text/javascript" src="script.js"></script>
> script.js has below variable.
>
> var MapColumns = 20, MapRows = 12;
>
> upon click of submit button in index.hmtl code,

..html, I hope.

> i want capture the values of r,c and update MapColumns, MapRows values
> in java script (script.js)

What do you wnt to do with it?

Change the serverside script.js?

Or enter them as variables in the new page?

> and reload the page , how can i do that.

use a <form> to send the values
and window.location.search to receive the string
and regex to get the values out of the string.

<http://www.w3schools.com/jsref/prop_loc_sear...

That is much easier using serverside coding, btw.

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

ram

9/1/2015 2:06:00 PM

0

techie24by7@gmail.com writes:
>upon click of submit button in index.hmtl code, i want
>capture the values of r,c and update MapColumns, MapRows
>values in java script (script.js) and reload the page , how
>can i do that.

This is one of the most common applications of JavaScript:
handling of an input event from a form button.

Therefore, it is usually treated in most of the tutorials.

Here is one example:

Main.html

<!DOCTYPE HTML><html><head><meta charset="UTF-8">
<title>Main</title><link rel="stylesheet" href="main.css">
</head><body>

<form id="form0">
<p><input id="text0" value="beta"></input></p>
<p><input id="button0" type="button" value="evaluate"></P>
</FORM>

<script type="application/javascript;version=1.8" src="main.js">
</script></body></html>

main.css

(main.css is empty)

The script is called at the end of the body so that the
page body can be rendered fast without being delayed by
the loading of the script.

The script shows how to display a simple alert when the
button is clicked:

main.js

"use strict";

function onButtonClick()
{ "use strict";
alert( document.getElementById( "text0" ).value ); }

function wireButton()
{ "use strict";
document.getElementById( "button0" ).
addEventListener( "click", onButtonClick ); }

function onDOMContentLoaded()
{ "use strict";
wireButton(); }

function wireDOMContentLoaded()
{ "use strict";
document.addEventListener
( "DOMContentLoaded", onDOMContentLoaded, false ); }

wireDOMContentLoaded();

»wireDOMContentLoaded« will add »DOMContendLoaded« as an event
listener that will be called when the DOM content is loaded.

This in turn will wire »onButtonClick« as a an event listener
that will be called when the button has been clicked.

When the HTML file is displayed in a recent Firefox and the
button is being clicked, the alert with a text from a field
of the form should be display.

Instead of displaying an alert, you also could set your
global variables.

The above might only work under a recent Mozilla Firefox, it
still has to be modified to work under more widely used browsers.

JJ

9/1/2015 3:13:00 PM

0

On Tue, 1 Sep 2015 05:44:31 -0700 (PDT), techie24by7@gmail.com wrote:
> Hello All,
>
> How you doing.
>
> I have a requirement to change SVG drawn image dynamically based on user
> given inputs from UI screen. The inputs are rows and columns.
>
> below is html code
> ------------------
>
> <!DOCTYPE html>
> <html>
> <head>
> <meta http-equiv="Content-Type" content="text/html;charset=utf-8">
> <title>Self Organizing Maps</title>
>
> <script type="text/javascript" src="http://d3js.org/d3.v3.js"></...
> <script type="text/javascript" src="http://d3js.org/d3.hexbin.v0.min.js"></...
> <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.3/jquery.js"></...
>
> <script>
>
> function handleIt(){
>
> r = document.getElementById('r').value;
> c = document.getElementById('c').value;
> p = document.getElementById('p').value;
>
> alert(r+''+c+''+p);
>
> MapColumns=c;
> MapRows=r;
>
> }
>
> </script>
>
> </head>
> <body>
> <div style="width:100%;">
> <div id="header">
> <h1>Map</h1>
> </div>
> <div id="nav">
>
> <form action="javascript:handleIt()">
> Row#<br>
> <input type="text" id="r" name="row" value="12" size="4" maxlength="4">
> <br>
> Column#<br>
> <input type="text" id="c" name="column" value="20" size="4" maxlength="4">
> <br>
> Size of Cell<br>
> <input type="text" id="p" name="cell" value="50" size="4" maxlength="4"> px
> <br>
> <input type="**submit**" value="GO">
> </form>
> </div>
> <div style="float:right; width:90%;">
> <div id="chart" style="overflow:auto; "></div>
> <script type="text/javascript" src="script.js"></script>
> </div>
> </div>
> </body>
> </html>
>
> In above index.html i have external java script being referred.
>
> <script type="text/javascript" src="script.js"></script>
> script.js has below variable.
>
> var MapColumns = 20, MapRows = 12;
>
> upon click of submit button in index.hmtl code, i want capture the values
> of r,c and update MapColumns, MapRows values in java script (script.js)
> and reload the page , how can i do that.

You might want to use local storage to store the form data.

With local storage, the handleIt() function would be like this.

function handleIt() {

r = document.getElementById('r').value;
c = document.getElementById('c').value;
p = document.getElementById('p').value;

alert(r+''+c+''+p);

c = parseInt(c.trim()); //or use regex for better string trimming
r = parseInt(r.trim());

if ((c > 0) && (r > 0)) {
//i.e. must be valid positive integer numbers

localStorage.setItem('MapColumns', c);
localStorage.setItem('MapRows', r);

MapColumns = c;
MapRows = r;

location.reload();

} else {

alert('Invalid map column / row value.');

}

}

And both map variable declarations in script.js would be like this.

var MapColumns = parseInt(localStorage.getItem("MapColumns")) || 20,
MapRows = parseInt(localStorage.getItem("MapRows")) || 12;

If your script has a function to update the SVG view based on new column and
row values, you can call that function instead of reloading the page. This
can save your server bandwidth as well as improve the web application
performance.