Solved

Radio buttons? how to change them automatically ?

Posted on 1998-09-30
7
138 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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 

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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
ASP:Radiobuttonlist/asp:RadioButtonListItem custom styling 1 42
Not seen Link button 5 39
Input box width 6 26
How to make footer stick to bottom 9 29
This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
Finding original email is quite difficult due to their duplicates. From this article, you will come to know why multiple duplicates of same emails appear and how to delete duplicate emails from Outlook securely and instantly while vital emails remai…
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

773 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