Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 09-12-2012, 11:14 PM   PM User | #1
wcoil
New to the CF scene

 
Join Date: Sep 2012
Posts: 2
Thanks: 1
Thanked 0 Times in 0 Posts
wcoil is an unknown quantity at this point
Set multiple values for one field

Hello all,
New to the forum today. I am working on a form for a client and I am trying to get a radio button to be able to output two values and don't know how to do this.
For example, when a customer clicks on the New PC Purchase option it outputs the value of the text "new pc purchase" into textfield1 and then it also outputs the text "649.95" into textfield2.

This is the script that I have in place which returns the 649.95 only into a text field titled cost4output

<script type="text/javascript" src="http://o.aolcdn.com/dojo/1.1.0/dojo/dojo.xd.js"></script>
<script type="text/javascript">
dojo.addOnLoad(function () {
dojo.connect(dojo.byId("container2"), "onclick",
function () {
dojo.byId("cost4output").value = dojo.map(
dojo.filter(
dojo.query("#container2 [type='radio']"),
"return item.checked"
),
"return item.value"
)
multiply();
}
)
})
</script>

And here is the html snippet which has the output fields listed. The current code is working for the cost4output field. The second field which we would like to have the "new pc purchase" entered is called hardware_4

<input type=text name="cost4" onchange="addition()" value="" size="10" id="cost4output" class="totalField">
<input type="text" name="hardware4" id="hardware_4" size="55" />


And here is the html for the actual radio buttons.
<div id="container2"><font size="+1"><strong>Low End PC</font><br /><center>
outright
<input type="radio" name="radiogroup2" id="radiogroup2_0" value="649.95" />
2yr
<input type="radio" name="radiogroup2" id="radiogroup2_1" value="549.95" />
3yr
<input type="radio" name="radiogroup2" id="radiogroup2_2" value="449.95" />
</div>


Any help would be appreciated.
wcoil is offline   Reply With Quote
Old 09-13-2012, 04:01 AM   PM User | #2
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,653
Thanks: 4
Thanked 2,451 Times in 2,420 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
Despite the similar sounding names, Java is not the same as Javascript.
Moving from Java forum to Javascript forum.
Fou-Lu is offline   Reply With Quote
Old 09-13-2012, 05:28 AM   PM User | #3
xelawho
Senior Coder

 
xelawho's Avatar
 
Join Date: Nov 2010
Posts: 2,437
Thanks: 52
Thanked 454 Times in 452 Posts
xelawho will become famous soon enoughxelawho will become famous soon enough
I don't know anything about dojo, but it looks like you can do something like this:
Code:
<script type="text/javascript">
dojo.addOnLoad(function () {
dojo.connect(dojo.byId("container2"), "onclick",
function () {
dojo.byId("hardware_4").value = dojo.map(
dojo.filter(
dojo.query("#container2 [type='radio']"),
"return item.checked"
),	
"return item.value.split('|')[0]"
)
dojo.byId("cost4output").value = dojo.map(
dojo.filter(
dojo.query("#container2 [type='radio']"),
"return item.checked"
),	
"return item.value.split('|')[1]"
)
multiply();
}
)
})
</script>
</head>
<body>
<input type=text name="cost4" onchange="addition()" value="" size="10" id="cost4output" class="totalField">
<input type="text" name="hardware4" id="hardware_4" size="55" />


<div id="container2"><font size="+1"><strong>Low End PC</font><br /><center>
outright
<input type="radio" name="radiogroup2" id="radiogroup2_0" value="new pc purchase|649.95" />
2yr
<input type="radio" name="radiogroup2" id="radiogroup2_1" value="reconditioned pc purchase|549.95" />
3yr
<input type="radio" name="radiogroup2" id="radiogroup2_2" value="crapped out pc purchase|449.95" />
</div>

</body>
xelawho is offline   Reply With Quote
Users who have thanked xelawho for this post:
wcoil (09-13-2012)
Old 09-13-2012, 01:15 PM   PM User | #4
wcoil
New to the CF scene

 
Join Date: Sep 2012
Posts: 2
Thanks: 1
Thanked 0 Times in 0 Posts
wcoil is an unknown quantity at this point
Smile working great!

Quote:
Originally Posted by xelawho View Post
I don't know anything about dojo, but it looks like you can do something like this:
Code:
<script type="text/javascript">
dojo.addOnLoad(function () {
dojo.connect(dojo.byId("container2"), "onclick",
function () {
dojo.byId("hardware_4").value = dojo.map(
dojo.filter(
dojo.query("#container2 [type='radio']"),
"return item.checked"
),	
"return item.value.split('|')[0]"
)
dojo.byId("cost4output").value = dojo.map(
dojo.filter(
dojo.query("#container2 [type='radio']"),
"return item.checked"
),	
"return item.value.split('|')[1]"
)
multiply();
}
)
})
</script>
</head>
<body>
<input type=text name="cost4" onchange="addition()" value="" size="10" id="cost4output" class="totalField">
<input type="text" name="hardware4" id="hardware_4" size="55" />


<div id="container2"><font size="+1"><strong>Low End PC</font><br /><center>
outright
<input type="radio" name="radiogroup2" id="radiogroup2_0" value="new pc purchase|649.95" />
2yr
<input type="radio" name="radiogroup2" id="radiogroup2_1" value="reconditioned pc purchase|549.95" />
3yr
<input type="radio" name="radiogroup2" id="radiogroup2_2" value="crapped out pc purchase|449.95" />
</div>

</body>
This worked Great thanks for the quick reply!!
wcoil is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 04:01 AM.


Advertisement
Log in to turn off these ads.