By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,916 Members | 1,068 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,916 IT Pros & Developers. It's quick & easy.

Need to return string and write generic script

P: n/a
<disclaimer>js newbie</disclaimer>

My page has a form comprised of several radio buttons. I want to poll the
buttons to determine which button was selected and convert its value to a
string. I then want to use the string on the same page.

My script is:

function checkRadio(field) {
for(var i=0; i < field.length; i++) {
if(field[i].checked) return field[i].value;
}
return false;
}
function checkFormLeft()
{
if(radioValue = checkRadio(form1.p1_p6_left)) {
if (radioValue == 0) {$syml = 'Uniform Thermal Pattern';}
if (radioValue == 10) {$syml = 'regular thermovascular pattern';}
if (radioValue == 20) {$syml = 'thermovascular network';}
if (radioValue == 25) {$syml = 'irregular thermovascular
pattern';}
if (radioValue == 40) {$syml = 'distorted thermovascular
pattern';}
if (radioValue == 60) {$syml = 'anarchic thermovascular pattern';}
alert("You selected " + $syml);
}
}

I call the script using onClick="checkForm()"

I added the alerts so I could verify the script is working. It is, but
when I try to use either $syml on the page calling the script, I get
nothing, e.g., 'The veins are $syml.' gives me 'The veins are.'

How do I use the string?

Question 2:

I have several pages with multiple radio (and checkbox) arrays. I'd like
to use a single js script for all of them. The 'p1_p6_left' in the above
is the common name of the radio button array. How do I write
'checkRadio(form1.p1_p6_left)' so I can pass different values in place of
p1_p6_left?

TIA (again)

--
Ed Jay (remove M to respond by email)
Dec 5 '05 #1
Share this Question
Share on Google+
18 Replies


P: n/a
Ed Jay wrote on 05 dec 2005 in comp.lang.javascript:
<disclaimer>js newbie</disclaimer>
[..]
if (radioValue == 60) {$syml = 'anarchic thermovascular pattern';}


"$syml" what langiage is that?
Not clientside Javascript surely?

Could it be,
that you try to set a serverside [php?] variable on the client?

If so, remember that the server is another machine.

--
Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress)

Dec 5 '05 #2

P: n/a

Ed Jay wrote:
<disclaimer>js newbie</disclaimer>

My page has a form comprised of several radio buttons. I want to poll the
buttons to determine which button was selected and convert its value to a
string. I then want to use the string on the same page.

My script is:

function checkRadio(field) {
for(var i=0; i < field.length; i++) {
if(field[i].checked) return field[i].value;
}
return false;
}
function checkFormLeft()
{
if(radioValue = checkRadio(form1.p1_p6_left)) {
if (radioValue == 0) {$syml = 'Uniform Thermal Pattern';}
if (radioValue == 10) {$syml = 'regular thermovascular pattern';}
if (radioValue == 20) {$syml = 'thermovascular network';}
if (radioValue == 25) {$syml = 'irregular thermovascular
pattern';}
if (radioValue == 40) {$syml = 'distorted thermovascular
pattern';}
if (radioValue == 60) {$syml = 'anarchic thermovascular pattern';}
alert("You selected " + $syml);
}
}


Values are always a string, but you're checking against a number.
Also, it would look better if you used a switch statement instead when
you're doing a lot of "ifs". For example:

switch(radioValue)
{
case "0":
$syml = "Uniform Thermal Pattern";
break;
case "10":
$syml = "thermovascular network";
break;
...[add more cases]...
default:
$syml = "none of the above";
break;
}

Dec 5 '05 #3

P: n/a

Evertjan. wrote:
"$syml" what langiage is that?
Not clientside Javascript surely?


Yes, javascript does allow the use of '$' as an identifier. But as you
said, it can potentially become confusing to differentiate between
javascript and php.

Dec 5 '05 #4

P: n/a
"Evertjan." <ex**************@interxnl.net> wrote:
Ed Jay wrote on 05 dec 2005 in comp.lang.javascript:
<disclaimer>js newbie</disclaimer>
[..]
if (radioValue == 60) {$syml = 'anarchic thermovascular pattern';}


"$syml" what langiage is that?
Not clientside Javascript surely?


It's only a label that I assigned.
Could it be,
that you try to set a serverside [php?] variable on the client?
No.
If so, remember that the server is another machine.


Yes, I know. Thanks.

--
Ed Jay (remove M to respond by email)
Dec 5 '05 #5

P: n/a
"web.dev" <we********@gmail.com> wrote:

Ed Jay wrote:
<disclaimer>js newbie</disclaimer>

My page has a form comprised of several radio buttons. I want to poll the
buttons to determine which button was selected and convert its value to a
string. I then want to use the string on the same page.

My script is:

function checkRadio(field) {
for(var i=0; i < field.length; i++) {
if(field[i].checked) return field[i].value;
}
return false;
}
function checkFormLeft()
{
if(radioValue = checkRadio(form1.p1_p6_left)) {
if (radioValue == 0) {$syml = 'Uniform Thermal Pattern';}
if (radioValue == 10) {$syml = 'regular thermovascular pattern';}
if (radioValue == 20) {$syml = 'thermovascular network';}
if (radioValue == 25) {$syml = 'irregular thermovascular
pattern';}
if (radioValue == 40) {$syml = 'distorted thermovascular
pattern';}
if (radioValue == 60) {$syml = 'anarchic thermovascular pattern';}
alert("You selected " + $syml);
}
}
Values are always a string, but you're checking against a number.


I'm checking a number so I can assign the appropriate string. I don't get
your point.
Also, it would look better if you used a switch statement instead when
you're doing a lot of "ifs". For example:

switch(radioValue)
{
case "0":
$syml = "Uniform Thermal Pattern";
break;
case "10":
$syml = "thermovascular network";
break;
...[add more cases]...
default:
$syml = "none of the above";
break;
}

Thanks for the tip, but I still need my two questions answered.

--
Ed Jay (remove M to respond by email)
Dec 5 '05 #6

P: n/a
web.dev wrote on 05 dec 2005 in comp.lang.javascript:
[..]
Values are always a string, but you're checking against a number.
Also, it would look better if you used a switch statement instead when
you're doing a lot of "ifs". For example:

switch(radioValue)
{
case "0":


Or use an array:

<script type='text/javascript'>

var s= [
'Uniform Thermal Pattern',
'regular thermovascular pattern',
'thermovascular network',
'irregular thermovascular pattern',
'distorted thermovascular pattern',
'anarchic thermovascular pattern'
]

function checkRadio(field) {
for(var i=0; i < field.length; i++)
if(field[i].checked)
alert('You selected:\n' + s[i]);
return false;
}

</script>

<form onsubmit='return checkRadio(this.r1)'>
<input type='radio' name='r1'>0
<input type='radio' name='r1'>10
<input type='radio' name='r1'>20
<input type='radio' name='r1'>25
<input type='radio' name='r1'>40
<input type='radio' name='r1'>60
<input type='submit'>
</form>
--
Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress)

Dec 5 '05 #7

P: n/a

Ed Jay wrote:
"web.dev" <we********@gmail.com> wrote:

Values are always a string, but you're checking against a number.


I'm checking a number so I can assign the appropriate string. I don't get
your point.


Following your style of programming, if I were to do what you were
doing, it would instead be this:

if(radioValue == "0")
....
else if(radio Value == "10")
....

The values you you get from the fields are *strings* not a number.
Therefore, checking against a number will not work. You need to check
against another string value.

Dec 5 '05 #8

P: n/a
"web.dev" <we********@gmail.com> wrote:

Ed Jay wrote:
"web.dev" <we********@gmail.com> wrote:
>Values are always a string, but you're checking against a number.


I'm checking a number so I can assign the appropriate string. I don't get
your point.


Following your style of programming, if I were to do what you were
doing, it would instead be this:

if(radioValue == "0")
...
else if(radio Value == "10")


Why use 'else' if it's not needed?...

The values you you get from the fields are *strings* not a number.
Therefore, checking against a number will not work. You need to check
against another string value.


I understand what you're saying, but it seems to be working, except as
noted in my original questions.

My buttons have numerical values, i.e., 'value = 10' not 'value = "10",'
so aren't they numbers I'm checking against?

As I say, except for my original questions, when I click a button, the
alert window comes up with the correct string ($syml).

--
Ed Jay (remove M to respond by email)
Dec 5 '05 #9

P: n/a
Lee <RE**************@cox.net> wrote:
Ed Jay said:

<disclaimer>js newbie</disclaimer>

My page has a form comprised of several radio buttons. I want to poll the
buttons to determine which button was selected and convert its value to a
string. I then want to use the string on the same page.

My script is:

function checkRadio(field) {
for(var i=0; i < field.length; i++) {
if(field[i].checked) return field[i].value;
}
return false;
}
function checkFormLeft()
{
if(radioValue = checkRadio(form1.p1_p6_left)) {
if (radioValue == 0) {$syml = 'Uniform Thermal Pattern';}
if (radioValue == 10) {$syml = 'regular thermovascular pattern';}
if (radioValue == 20) {$syml = 'thermovascular network';}
if (radioValue == 25) {$syml = 'irregular thermovascular
pattern';}
if (radioValue == 40) {$syml = 'distorted thermovascular
pattern';}
if (radioValue == 60) {$syml = 'anarchic thermovascular pattern';}
alert("You selected " + $syml);
}
}

I call the script using onClick="checkForm()"
Obviously that's not really how you're calling checkFormLeft().


:-) You're correct...I call it as checkFormLeft().
Are you calling checkFormLeft() from within a function that
contains "var $syml"?
No. I'm simply calling it with an onClick event from within a form input
element, e.g., <input name=xyz value=25 onClick="checkFormLeft();">
If so, you've declared the variable to
be local to that function, so you can't set its value in another.
If all checkFormLeft() does is set the value of that variable,
have it return that value, rather than assign to a global.


I don't understand. One of my questions was 'how do I return the variable
so I can use it on the calling page?'

--
Ed Jay (remove M to respond by email)
Dec 5 '05 #10

P: n/a
Ed Jay wrote:
<disclaimer>js newbie</disclaimer>

My page has a form comprised of several radio buttons. I want to poll the
buttons to determine which button was selected and convert its value to a
string. I then want to use the string on the same page.

My script is:

function checkRadio(field) {
for(var i=0; i < field.length; i++) {
if(field[i].checked) return field[i].value;
}
return false;
There is no need to return false.

}
function checkFormLeft()
{
if(radioValue = checkRadio(form1.p1_p6_left)) {
If the value of 'radioValue' is ever set to zero, this assignment/test
will fail and your script will not run.

if (radioValue == 0) {$syml = 'Uniform Thermal Pattern';}
If all you want to do is return the string 'Uniform ...', then:

if (radioValue == 0) {return 'Uniform Thermal Pattern';}

But as Evertjan suggested, the values are much better off in an array
or object and you can ditch all those conditional statements.

if (radioValue == 10) {$syml = 'regular thermovascular pattern';}
if (radioValue == 20) {$syml = 'thermovascular network';}
if (radioValue == 25) {$syml = 'irregular thermovascular
pattern';}
if (radioValue == 40) {$syml = 'distorted thermovascular
pattern';}
if (radioValue == 60) {$syml = 'anarchic thermovascular pattern';}
alert("You selected " + $syml);
}
}

Then have a function that writes the value to the page:

function writeButtonValue(elementID)
{
var txt = checkFormLeft();
document.getElementById(elementID).innerHTML = txt;
}

Instead of calling checkFormLeft from the page, call writeButtonValue
and pass it the ID of the element you want to write the value into.

I call the script using onClick="checkForm()"

I added the alerts so I could verify the script is working. It is, but
when I try to use either $syml on the page calling the script, I get
nothing, e.g., 'The veins are $syml.' gives me 'The veins are.'
Because you created $sml as a local variable within checkFormLeft so
it is not accessible to functions outside checkFormLeft.


How do I use the string?

Question 2:

I have several pages with multiple radio (and checkbox) arrays. I'd like
to use a single js script for all of them. The 'p1_p6_left' in the above
is the common name of the radio button array. How do I write
'checkRadio(form1.p1_p6_left)' so I can pass different values in place of
p1_p6_left?


Pass it from the onclick:

onclick="checkForm('p1_p6_left');"
And then checkFormLeft becomes:

function checkFormLeft( butSet )
{
if(radioValue = checkRadio(form1[butSet])) {
...
}

Or if you use the suggested writeButtonValue, pass an element ID and
the button set name:
onclick="writeButtonValue('elementID','p1_p6_left' );"
function writeButtonValue(elementID, elementName)
{
var txt = checkFormLeft(elementName);
document.getElementById(elementID).innerHTML = txt;
}

--
Rob
Dec 5 '05 #11

P: n/a
RobG <rg***@iinet.net.auau> wrote:
Ed Jay wrote:
<disclaimer>js newbie</disclaimer>

My page has a form comprised of several radio buttons. I want to poll the
buttons to determine which button was selected and convert its value to a
string. I then want to use the string on the same page.

My script is:

function checkRadio(field) {
for(var i=0; i < field.length; i++) {
if(field[i].checked) return field[i].value;
}
return false;
There is no need to return false.

}
function checkFormLeft()
{
if(radioValue = checkRadio(form1.p1_p6_left)) {


If the value of 'radioValue' is ever set to zero, this assignment/test
will fail and your script will not run.

if (radioValue == 0) {$syml = 'Uniform Thermal Pattern';}


If all you want to do is return the string 'Uniform ...', then:

if (radioValue == 0) {return 'Uniform Thermal Pattern';}


I want to be able to use the string in text in multiple places on the
page. Using 'return 'string' do I call the script each time I want to use
the string?
But as Evertjan suggested, the values are much better off in an array
or object and you can ditch all those conditional statements.

if (radioValue == 10) {$syml = 'regular thermovascular pattern';}
if (radioValue == 20) {$syml = 'thermovascular network';}
if (radioValue == 25) {$syml = 'irregular thermovascular
pattern';}
if (radioValue == 40) {$syml = 'distorted thermovascular
pattern';}
if (radioValue == 60) {$syml = 'anarchic thermovascular pattern';}
alert("You selected " + $syml);
}
}

Then have a function that writes the value to the page:

function writeButtonValue(elementID)
{
var txt = checkFormLeft();
document.getElementById(elementID).innerHTML = txt;
}

Instead of calling checkFormLeft from the page, call writeButtonValue
and pass it the ID of the element you want to write the value into.

I call the script using onClick="checkForm()"

I added the alerts so I could verify the script is working. It is, but
when I try to use either $syml on the page calling the script, I get
nothing, e.g., 'The veins are $syml.' gives me 'The veins are.'


Because you created $sml as a local variable within checkFormLeft so
it is not accessible to functions outside checkFormLeft.


How do I use the string?

Question 2:

I have several pages with multiple radio (and checkbox) arrays. I'd like
to use a single js script for all of them. The 'p1_p6_left' in the above
is the common name of the radio button array. How do I write
'checkRadio(form1.p1_p6_left)' so I can pass different values in place of
p1_p6_left?


Pass it from the onclick:

onclick="checkForm('p1_p6_left');"
And then checkFormLeft becomes:

function checkFormLeft( butSet )
{
if(radioValue = checkRadio(form1[butSet])) {
...
}


Thanks.
Or if you use the suggested writeButtonValue, pass an element ID and
the button set name:
onclick="writeButtonValue('elementID','p1_p6_left' );"
function writeButtonValue(elementID, elementName)
{
var txt = checkFormLeft(elementName);
document.getElementById(elementID).innerHTML = txt;
}


I don't want to assign the resulting $syml to a button. I want to use it
several places on the page.

--
Ed Jay (remove M to respond by email)
Dec 5 '05 #12

P: n/a
Lee <RE**************@cox.net> wrote:
Ed Jay said:

Lee <RE**************@cox.net> wrote:
Ed Jay said:

<disclaimer>js newbie</disclaimer>

My page has a form comprised of several radio buttons. I want to poll the
buttons to determine which button was selected and convert its value to a
string. I then want to use the string on the same page.

My script is:

function checkRadio(field) {
for(var i=0; i < field.length; i++) {
if(field[i].checked) return field[i].value;
}
return false;
}
function checkFormLeft()
{
if(radioValue = checkRadio(form1.p1_p6_left)) {
if (radioValue == 0) {$syml = 'Uniform Thermal Pattern';}
if (radioValue == 10) {$syml = 'regular thermovascular pattern';}
if (radioValue == 20) {$syml = 'thermovascular network';}
if (radioValue == 25) {$syml = 'irregular thermovascular
pattern';}
if (radioValue == 40) {$syml = 'distorted thermovascular
pattern';}
if (radioValue == 60) {$syml = 'anarchic thermovascular pattern';}
alert("You selected " + $syml);
}
}

I call the script using onClick="checkForm()"

Obviously that's not really how you're calling checkFormLeft().
:-) You're correct...I call it as checkFormLeft().
Are you calling checkFormLeft() from within a function that
contains "var $syml"?


No. I'm simply calling it with an onClick event from within a form input
element, e.g., <input name=xyz value=25 onClick="checkFormLeft();">
If so, you've declared the variable to
be local to that function, so you can't set its value in another.
If all checkFormLeft() does is set the value of that variable,
have it return that value, rather than assign to a global.


I don't understand. One of my questions was 'how do I return the variable
so I can use it on the calling page?'


My question was based on the assumption that checkFormLeft() is actually
called from checkForm().


Sorry, I misunderstood your question's intent.
How are you trying to use the variable? Remember that it won't have any
value until you click whatever button it is that calls your function.
Pressing any one of the first set of radio buttons brings up a menu of
checkboxes. Checking one or more of the checkboxes will bring up another
set of checkboxes. I'll call the checkFormLeft() function (or equivalent)
from the set of radio buttons. I then plan to use the resulting string
($syml) as part of the text for the first and second checkbox menus. The
title might look something like:

'Choose the regions in which the $syml is observed, then measure the
temperature of the $syml.'
Also, if you want your code to work in any browser other than Internet
Explorer, you should change "checkRadio(form1.p1_p6_left)" to
"checkRadio(document.form1.p1_p6_left)". Most browsers don't allow you
to refer to forms directly.
Thank you.
The following works:

<html>
<head>
<script type="text/javascript">
function checkRadio(field) {
for(var i=0; i < field.length; i++) {
if(field[i].checked) return field[i].value;
}
return false;
}
function checkFormLeft()
{
if(radioValue = checkRadio(document.form1.p1_p6_left)) {
// Note that I changed that to "document..." for browsers
// other than Internet Explorer
if (radioValue == 0) {$syml = 'Uniform Thermal Pattern';}
if (radioValue == 10) {$syml = 'regular thermovascular pattern';}
if (radioValue == 20) {$syml = 'thermovascular network';}
if (radioValue == 25) {$syml = 'irregular thermovascular pattern';}
if (radioValue == 40) {$syml = 'distorted thermovascular pattern';}
if (radioValue == 60) {$syml = 'anarchic thermovascular pattern';}
alert("You selected " + $syml);
}
}
</script>
</head>
<body>
<form name="form1">
0<input type="radio" value="0" name="p1_p6_left"><br>
10<input type="radio" value="10" name="p1_p6_left"><br>
20<input type="radio" value="20" name="p1_p6_left"><br>
25<input type="radio" value="25" name="p1_p6_left"><br>
40<input type="radio" value="40" name="p1_p6_left"><br>
60<input type="radio" value="60" name="p1_p6_left"><br>
<input type="button" onclick="checkFormLeft()" value="checkFormLeft()">
<br>
<input type="button" onclick="alert($syml)" value="alert($syml)">
</form>
</body>
</html>


Here's where I am--my code is now:

var s= [
'Uniform Thermal Pattern',
'regular thermovascular pattern',
'thermovascular network',
'irregular thermovascular pattern',
'distorted thermovascular pattern',
'anarchic thermovascular pattern'
]

function checkRadio(field) {
for(var i=0; i < field.length; i++)
if(field[i].checked)
alert(s[i]);
return false;
}

Calling it with onClick = "checkRadio(p1_p6.left)";

Once again, this works fine to the extent that the alerts show the
appropriate string; however, I still don't know how to use the result on
the calling page. I'm also going to want to pass the result to a cgi form
using a hidden input element.

(BTW, I say 'the calling page' because the js is remotely linked to the
page. I have several pages that want to use the same script, but with
different field names.)

Is it possible to use the above function with checkboxes instead of radio
buttons?

What if the field names aren't the same, but are serialized? For example,
say the checkboxes are named p1_p6_left_1, p1_p6_left_2...?

--
Ed Jay (remove M to respond by email)
Dec 6 '05 #13

P: n/a
Lee <RE**************@cox.net> wrote:
Ed Jay said:
I don't want to assign the resulting $syml to a button. I want to use it
several places on the page.
What do you mean by using it several places on the page?

First the entire page will be displayed.
Yes.
Then the user will select a radio box.
When the user selects a radio button, it displays a hidden menu of
checkboxes. I want this second menu to use the string result ($syml) in
the menu title and elsewhere.
Then the user will click a button.
From the second menu of checkboxes.
Then the value will be available.
I don't understand you.
What do you want to happen?


I want the value to be used to label the second menu and to be passed to
another form (page 2) using a hidden input element.

On the theory that one picture is worth a few words... Please go to
<http://www.edbj.aes-intl.com/cgi-bin/brca_mod13.pl>. On the menu "For
Each Breast, Select the venous Pattern Observed," click on "Anarchic
Thermovascular Pattern." An alert will pop up confirming that the js is
working. Note the (cyan) menu that appears at the bottom of the page. Note
that s[i] in the text? That's where I want the resulting string to appear
(as well as the hidden input element).

--
Ed Jay (remove M to respond by email)
Dec 6 '05 #14

P: n/a
Lee <RE**************@cox.net> wrote:
Ed Jay said:
On the theory that one picture is worth a few words... Please go to
<http://www.edbj.aes-intl.com/cgi-bin/brca_mod13.pl>. On the menu "For
Each Breast, Select the venous Pattern Observed," click on "Anarchic
Thermovascular Pattern." An alert will pop up confirming that the js is
working. Note the (cyan) menu that appears at the bottom of the page. Note
that s[i] in the text? That's where I want the resulting string to appear
(as well as the hidden input element).


At a glance, the problem may be as simple as the fact that you've
got your onclick handler defined to show the menu, and *then* check
to see which radio button is checked.

Try changing each occurance of:
onclick="show('div1');checkRadio(p1_p6_left);"
to:
onclick="checkRadio(p1_p6_left);show('div1');"


Doh! That wasn't the solution, but it's sure was a stupid error. :-)

Thanks for looking.

If I understand correctly, the value that is returned as $syml (or s[i] as
in my alternate attempt that didn't work either) is only known internally
to the function. Does my question then morph to 'how do I make a local
variable global to the page that called the function?'

I was planning to score the sum of multiple-checked boxes with the
following. How do I use 'score' outside of the function? I think that's
essentially one of the same questions I've been asking.

var score;
function checkRadio(field) {
for(var i=0; i < field.length; i++) {
score = (score + if(field[i].checked) return field[i].value);
}
}

--
Ed Jay (remove M to respond by email)
Dec 6 '05 #15

P: n/a
Ed Jay wrote:
"web.dev" <we********@gmail.com> wrote:
Ed Jay wrote:
"web.dev" <we********@gmail.com> wrote:
Values are always a string, but you're checking against a number.
I'm checking a number so I can assign the appropriate string. I don't get
your point. Following your style of programming, if I were to do what you were
doing, it would instead be this:

if(radioValue == "0")
...
else if(radio Value == "10")


Why use 'else' if it's not needed?


Because it's a waste of time to look to see whether something is equal
to "10" if you already know that it's equal to "0", and if you don't put
that "else" there, that's what the computer is going to do.
My buttons have numerical values, i.e., 'value = 10' not 'value = "10",'
so aren't they numbers I'm checking against?


No, your buttons have string values. They may happen to be strings that
are numbers, but they're still strings, because that's how HTML buttons
work. In order to compare "10" to 10, the computer has to do extra work.
(In a less forgiving language, in fact, you'd simply get an error
message that you are trying to compare apples and oranges, and your
program would stop dead.)

--
John W. Kennedy
"But now is a new thing which is very old--
that the rich make themselves richer and not poorer,
which is the true Gospel, for the poor's sake."
-- Charles Williams. "Judgement at Chelmsford"
Dec 6 '05 #16

P: n/a
web.dev wrote:
Evertjan. wrote:
"$syml" what langiage is that?
Not clientside Javascript surely?


Yes, javascript does allow the use of '$' as an identifier. But as you
said, it can potentially become confusing to differentiate between
javascript and php.


Or other programming languages, for that matter.
PointedEars
Dec 7 '05 #17

P: n/a
Thomas 'PointedEars' Lahn wrote on 07 dec 2005 in comp.lang.javascript:
web.dev wrote:
Evertjan. wrote:
"$syml" what langiage is that?
Not clientside Javascript surely?


Yes, javascript does allow the use of '$' as an identifier. But as you
said, it can potentially become confusing to differentiate between
javascript and php.


Or other programming languages, for that matter.


I'm glad you agree.
--
Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress)

Dec 7 '05 #18

P: n/a
Ed Jay wrote:

<disclaimer>js newbie</disclaimer>

After a day of learning, thank you, I have my situation down to...

The code:

var s= [
'Uniform Thermal Pattern',
'regular thermovascular pattern',
'thermovascular network',
'irregular thermovascular pattern',
'distorted thermovascular pattern',
'anarchic thermovascular pattern'
]

function checkRadio(field) {
for(var i=0; i < field.length; i++)
if(field[i].checked) {
return s[i];
}
s[i] = 'undefined pattern';
return s[i];
}

The function passes the common name of a set of radio buttons. It is
called from within a hidden container before the hidden container is made
visible. The container's visibility is toggled by whichever radio button
is checked. I have confirmed that the function works. I have also
confirmed that the inline script i=3; document.write(s[i]); writes the
correctly indexed array.

But...

When placed within html text at the position I want to publish the
selected and indexed phrase, the inline script
'document.write(checkRadio(field);' displays nothing. Neither does
'checkRadio(field); document.write(s[i]) never makes it past the
document.write() statement, at least other js-driven events stopped
executing.

It occurs to me that the only time my inline function is called is when
the page loads.

--
Ed Jay (remove M to respond by email)
Dec 8 '05 #19

This discussion thread is closed

Replies have been disabled for this discussion.