Solved

Radio buttons? how to change them automatically ?

Posted on 1998-09-30
7
141 Views
Last Modified: 2010-05-18
ok i am in an ASP file. I have made a simple sql which selects certain records in my "mytable" table. the sql works OK.
This is my problem. In a certain point in my script, one of the values which is selected (<%= rf.fields(2).value %>) is printed out as a radio button.(PS, there could be multiple values). Now when the user cheks this radio button, I need to change at the same time the value of a variable called size (which is going to be send through a POST)

for example:

One size             prix: $ 12.99 (radio button here)
Large                prix: $ 14.99 (radio button here)

Now when the user choses the first radio button (12.99) i need to assign automatically the right size to my variable called size.

<table width="80%" border="1">
<%
do while not rf.eof
  if rs.fields(2).value = rf.fields(0).value then
%>
<tr valign="top">
<td width="25%"><font face="Arial, Arial Narrow" size="2">
  <%=rf.fields(4).value %></font>
</td>
<td width="25%"><font face="Arial, Arial Narrow" size="2">Prix : $ <%= rf.fields(2).value %>
<input type="radio" name="prix"
   value="<%=rf.fields(2).value%>" CHECKED>
</td>
</tr>
<%
end if
rf.movenext
loop
rf.close
%>
<tr><td><font face="Arial, Arial Narrow" size="2">Quantité: <input type="text" name="qte" size="3" maxlength="3" value="1"></font></td><td colspan=2>
<input type="hidden" name="nomitem" value="<%=rs.fields(0).value%>">
<input type="submit" value="Commander"></td></tr>
</form>
</table>

This is a part of the code which i coded. If anyone can help me I appreciate it a lot. Thanks in advance.
0
Comment
Question by:AnitaP
  • 4
  • 3
7 Comments
 
LVL 28

Expert Comment

by:sybe
ID: 1838235
If you want to change a value that will be send with the form (called "size") then you will have to define this variable in your form. Best would be in a hidden field.

Using client side (java-)script, you can change the value of this field in response to the clicking of a button.

<script>
function ChangeSize(str) {
  document.forms['myForm'].size.value = str;
}
</script>

<form name="myForm">
<input type=hidden name=size>

<input type=radio name=prix value="12.99" onClick="ChangeSize(this.value)">
<input type=radio name=prix value="14.99" onClick="ChangeSize(this.value)">
</form>

Now when the form is submitted, it will also send a value for "size", which corresponds with the radio button clicked.

I don't know if this answers your question. If not, then I probably did not understand it.


0
 

Author Comment

by:AnitaP
ID: 1838236
What will this.value contain [ChangeSize(this.value)] when the ChangeSize function is called ?
0
 

Author Comment

by:AnitaP
ID: 1838237
Ok I got a small part working. I want to also send the name of the form through a parameter, like the str. One complication though the name of the form contains spaces in it. so when i try to receive it with space it gives me an error. here is what I did:

<script>
function ChangeSize(str,frm) {
  document.forms['this is the name of the form'].test.value=frm;
}
</script>

str: is a simple string which i want to use in a hidden
     input field.
frm: is the name of my form which i want to pass to my function
test: is just a simple input test box in which i display the
      value of my str

Sybe, Thanks for making me advance. if you know how can I fix this problem answer me.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:AnitaP
ID: 1838238
A detail:
<script>
function ChangeSize(str,frm) {
  document.forms['this is the name of the form'].test.value=frm;
}
</script>

str is gonna replace the string : 'this is the name of the form'

0
 
LVL 28

Expert Comment

by:sybe
ID: 1838239
If you have more than one form in the document, it might be usefull to pass the name of the form:

<script>
function ChangeSize(str,frm) {
  document.forms[frm].test.value=str;
}
</script>

<input type=radio name=prix value="12.99" onClick="ChangeSize(this.value,'myForm')">



Will change the value of field 'test' in the form 'myForm' to '12.99'.

As you see I changed the call in the radio button to pass 2 parameters.

About the spaces-problem, some solutions
1. don't use spaces in the name of the form
2. escape & unescape them:
  escape('this is a string with spaces') returns an encoded string without spaces. unescape(str) will bring the original string back.


0
 

Author Comment

by:AnitaP
ID: 1838240
Thanks Sybe. It works. I am endlessly greatfull :o)
0
 
LVL 28

Accepted Solution

by:
sybe earned 20 total points
ID: 1838241
np, just grade my answer :)
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
html border input line 7 26
email validation 9 48
Allow a tab area under the contents 1 24
Link Anchor Not working 9 47
Building a website can seem like a daunting task to the uninitiated but it really only requires knowledge of two basic languages: HTML and CSS.
When crafting your “Why Us” page, there are a plethora of pitfalls to avoid. Follow these five tips, and you’ll be well on your way to creating an effective page.
In this tutorial viewers will learn how to style transparent/translucent elements using alpha transparency in CSS Start with a normal styled element, such as a div.: Define its "background-color" property as "rgba (255, 255, 255, .5): The numbers in…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question