?
Solved

Radio buttons? how to change them automatically ?

Posted on 1998-09-30
7
Medium Priority
?
144 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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 80 total points
ID: 1838241
np, just grade my answer :)
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

This article describes how to create custom column layout styles for Bootstrap. The article uses 5 columns to illustrate the concept, but the principle can be extended to any number of columns.
Find out what you should include to make the best professional email signature for your organization.
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
The viewer will learn the basics of jQuery including how to code hide show and toggles. 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…
Suggested Courses

770 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