Solved

Radio buttons? how to change them automatically ?

Posted on 1998-09-30
7
136 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
Comment Utility
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
Comment Utility
What will this.value contain [ChangeSize(this.value)] when the ChangeSize function is called ?
0
 

Author Comment

by:AnitaP
Comment Utility
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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 

Author Comment

by:AnitaP
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks Sybe. It works. I am endlessly greatfull :o)
0
 
LVL 28

Accepted Solution

by:
sybe earned 20 total points
Comment Utility
np, just grade my answer :)
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

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…
Use these top 10 tips to master the art of email signature design. Create an email signature design that will easily wow recipients, promote your brand and highlight your professionalism.
In this tutorial viewers will learn how to code links for mobile sites that, once clicked, send a call or text to a specified number. For a telephone link (once clicked, calls a number), begin with a normal "<a href=" link tag. For the href, specify…
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 …

762 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now