473,763 Members | 1,794 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Need to return string and write generic script

<disclaimer>j s 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(fiel d) {
for(var i=0; i < field.length; i++) {
if(field[i].checked) return field[i].value;
}
return false;
}
function checkFormLeft()
{
if(radioValue = checkRadio(form 1.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="checkF orm()"

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(for m1.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
18 2268
Ed Jay wrote on 05 dec 2005 in comp.lang.javas cript:
<disclaimer>j s 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

Ed Jay wrote:
<disclaimer>j s 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(fiel d) {
for(var i=0; i < field.length; i++) {
if(field[i].checked) return field[i].value;
}
return false;
}
function checkFormLeft()
{
if(radioValue = checkRadio(form 1.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(radioVal ue)
{
case "0":
$syml = "Uniform Thermal Pattern";
break;
case "10":
$syml = "thermovasc ular network";
break;
...[add more cases]...
default:
$syml = "none of the above";
break;
}

Dec 5 '05 #3

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
"Evertjan." <ex************ **@interxnl.net > wrote:
Ed Jay wrote on 05 dec 2005 in comp.lang.javas cript:
<disclaimer>j s 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
"web.dev" <we********@gma il.com> wrote:

Ed Jay wrote:
<disclaimer>j s 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(fiel d) {
for(var i=0; i < field.length; i++) {
if(field[i].checked) return field[i].value;
}
return false;
}
function checkFormLeft()
{
if(radioValue = checkRadio(form 1.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(radioVa lue)
{
case "0":
$syml = "Uniform Thermal Pattern";
break;
case "10":
$syml = "thermovasc ular 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
web.dev wrote on 05 dec 2005 in comp.lang.javas cript:
[..]
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(radioVal ue)
{
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(fiel d) {
for(var i=0; i < field.length; i++)
if(field[i].checked)
alert('You selected:\n' + s[i]);
return false;
}

</script>

<form onsubmit='retur n 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

Ed Jay wrote:
"web.dev" <we********@gma il.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
"web.dev" <we********@gma il.com> wrote:

Ed Jay wrote:
"web.dev" <we********@gma il.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(radioValu e == "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
Lee <RE************ **@cox.net> wrote:
Ed Jay said:

<disclaimer>j s 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(fiel d) {
for(var i=0; i < field.length; i++) {
if(field[i].checked) return field[i].value;
}
return false;
}
function checkFormLeft()
{
if(radioValue = checkRadio(form 1.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="checkF orm()"
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="checkF ormLeft();">
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

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

Similar topics

2
3056
by: lawrence | last post by:
I've been bad about documentation so far but I'm going to try to be better. I've mostly worked alone so I'm the only one, so far, who's suffered from my bad habits. But I'd like other programmers to have an easier time understanding what I do. Therefore this weekend I'm going to spend 3 days just writing comments. Before I do it, I thought I'd ask other programmers what information they find useful. Below is a typical class I've...
10
3788
by: Nikita A. Visnevski | last post by:
Hi everyone, I am rather new to Java beans. Just picked up a book last night and started reading about them. I am building an application that allows a user to define objects with dynamic properties. Something similar to a java hash table. One can add new properties at runtime and remove them as well. I have a really fancy third party property inspector available to me that I would very much like to reuse. This inspector uses...
2
2937
by: Mike Button | last post by:
Hello all, I am really really desperate on what I should do, and I am asking for help from anyone in this newsgroup, here's the situation: I am creating a form that is being run on a server where there is no scripts allowed running (the software is from Opentext called Livelink)- therefore I need javascript to do the tasks listed below: 1. validate the form - this has been completed 2. pop up another window that will go ahead and...
7
2360
by: Jack Addington | last post by:
I've got a fairly simple application implementation that over time is going to get a lot bigger. I'm really trying to implement it in a way that will facilitate the growth. I am first writing a WinForms interface and then need to port that to a web app. I am kinda stuck on a design issue and need some suggestions / direction. Basically I have a business layer that I want to use to process any dataentry logic (row focus changes, data...
3
1939
by: Sky Sigal | last post by:
I coming unglued... really need some help. 3 days chasing my tail all over MSDN's documentation ...and I'm getting nowhere. I have a problem with TypeConverters and storage of expandableobjects to attributes in tags (think Style tag -> Style object). The problem that I am chasing is: Html side:
0
1352
by: Miguel Dias Moura | last post by:
Hello, I am saving a complex type in Asp.Net 2.0 profile. I am using an SQL 2005 database as a profile provider. I have been consulting MSDN as help to create my class. (Please, see my code at the end of this post) OBJECTIVE: - Save the documents published by each user in profile.
1
4035
by: jens Jensen | last post by:
Hello , i'm calling a webservice generated with oracle webservice java tools. I'm not able to add a web reference to a .net client the usual way with visual studio 2005. I was therefore provided with a set of Dll that implement the proxy needed to consume this web service. I'm now wrapping these dlls in a .Net webservice that can be consumed with Visual studio the familliar way.
8
2086
by: pamelafluente | last post by:
I am beginning aspNet, I know well win apps. Need a simple and schematic code example to start work. This is what I need to accomplish: ---------------------- Given button and a TextBox on a web form when one presses the button on the web form on a client pc, the sql query which is contained in the text box is sent to a vb net application on a server pc. The win application sends the query to the database, collects the results,
1
1130
by: shapper | last post by:
Hello, I created a user control (.ascx) with a property as follows: Private _Messages As Generic.List(Of String) Public Property Messages() As Generic.List(Of String) Get Return _Messages End Get Set(ByVal value As Generic.List(Of String))
0
9383
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
10140
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...
1
9935
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8821
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
7364
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
5268
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5405
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3519
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2790
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.