Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Radio buttons? how to change them automatically ?

Posted on 1998-09-30
7
Medium Priority
?
145 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
Industry Leaders: 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 80 total points
ID: 1838241
np, just grade my answer :)
0

Featured Post

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!

Question has a verified solution.

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

Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

618 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