swaggerking
asked on
Javascript add input radio value to a parameter of a query string
I'm working in classic asp and I have a form that I want to add the value of the radio button to a url with parameters. mypage.asp?party=yes or mypage.asp?party=no
<label>Go To party</label><br />
<input type="radio" name="party" id="rsvpyes" value="yes" /><br />
<input type="radio" name="party" id="rsvpno" value="no" /><br />
<a href="mypage.asp?party=yes">RSVP</a> or
<a href="mypage.asp?party=no">RSVP</a>
Is this what you mean? http://jsbin.com/emIPiHuW/1/edit?html,js,output
Did you want to click the link? or the radio?
function getParty()
{
var party = document.getElementsByName('party');
for (var i = 0, length = party.length; i < length; i++) {
if (party[i].checked) {
//alert(party[i].value);
window.location='mypage.asp?party='+party[i].value;
break;
}
}
}
<label>Go To party</label><br />
<input type="radio" name="party" id="rsvpyes" value="yes" /><br />
<input type="radio" name="party" id="rsvpno" value="no" /><br />
<a href="#mypage.asp?party=yes" onclick="getParty()">RSVP</a> or
<a href="#mypage.asp?party=no" onclick="getParty()">RSVP</a>
Did you want to click the link? or the radio?
As Dave has said why not use a form but with jquery
http://jsfiddle.net/GaryC123/c2Np6/4/
http://jsfiddle.net/GaryC123/c2Np6/4/
<label>Go To party</label><br />
<input type="radio" name="party" id="rsvpyes" value="yes" />Yes<br />
<input type="radio" name="party" id="rsvpno" value="no" />No<br />
<a href="mypage.asp?">RSVP</a>
$("a").click(function(){
$(this).attr("href",$(this).attr("href") + "party="+$(":radio[name=party]:checked").val())
})
ASKER
Dave GET won't work in this scenario.
Scott and Padas,
Very close to what I need but I should have been more clear with my question. My apologies, so I will increase points.
My form POST but redirects to "thankyoupage.asp" based upon a value in a hidden input. I need to add/append "yes" or "no" to the end of "thankyoupage.asp?party=" so I can display the correct message dependent on whether they can attend or not attend party.
Again, sorry for not being clearer.
Scott and Padas,
Very close to what I need but I should have been more clear with my question. My apologies, so I will increase points.
My form POST but redirects to "thankyoupage.asp" based upon a value in a hidden input. I need to add/append "yes" or "no" to the end of "thankyoupage.asp?party=" so I can display the correct message dependent on whether they can attend or not attend party.
<form action="somepage.asp" method="post" name="form" >
<input type="radio" name="party" id="rsvpyes" value="yes" /> YES<br />
<input type="radio" name="party" id="rsvpno" value="no" /> NO<br />
<button name="Submit" type="submit" value="Submit" />RSVP</button>
<input type="hidden" name="confirm page" value="thankyoupage.asp?party=">
</form>
Again, sorry for not being clearer.
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
when posting your page to somepage.asp, the script(somepage.asp) know if party is << yes >> or << no >>
so why do you need an hidden field ?
just concatenate the party query string value to your redirect string :
so why do you need an hidden field ?
just concatenate the party query string value to your redirect string :
Response.Redirect "http://www.w3schools.com?party=" & Request.QueryString("party")
%>
SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
There really is no need to use js or jquery on this page. The user selects yes or no then clicks the submit button. Then on the somepage.asp you would use
<%
party="no"
if request.form("party")<>"" then
if request.form("party")="yes" then
party="yes"
end if
' later in the page
if party="yes" then
response.write "Thank you for coming to my party"
else
response.write "I am sorry you can not come to my party"
end if
%>
There you go, @swaggerking , three almost identical suggestions in a row as soon as we knew enough about what you were trying to do.
ASKER
I hear you guys loud and clear and I agree with you 100%. Unfortunately I don't have access to "somepage.asp". Somepage.asp is actually an internal form processing script. Internally we use this to process any inet form and redirect to any page using the hidden input "confirm page".
GaryC123,
This only adds the value "yes" or "no" to the hidden
example:
<input type="hidden" name="confirmpage" value="yes">
or
<input type="hidden" name="confirmpage" value="no">
I'd prefer:
<input type="hidden" name="confirmpage" value="thankyoupage.asp?pa rty=yes">
or
<input type="hidden" name="confirmpage" value="thankyoupage.asp?pa rty=no">
GaryC123,
<script>
$("[name=form]").submit(function(){
$("[name='confirm page']").val($(this).val() + $(":radio[name=party]:checked").val())
})
</script>
This only adds the value "yes" or "no" to the hidden
example:
<input type="hidden" name="confirmpage" value="yes">
or
<input type="hidden" name="confirmpage" value="no">
I'd prefer:
<input type="hidden" name="confirmpage" value="thankyoupage.asp?pa
or
<input type="hidden" name="confirmpage" value="thankyoupage.asp?pa
SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
Too late for me to test this now but if it is only setting the value to yes/no then change the script to
edit
I see why now
Still confused as to the logic behind this.
<script>
$("[name=form]").submit(function(){
$("[name='confirm page']").val($("[name='confirm page']").val + $(":radio[name=party]:checked").val())
})
</script>
edit
I see why now
Still confused as to the logic behind this.
ASKER
I got working with your suggestions. Much appreciation.
Open in new window