Click to See Complete Forum and Search --> : Need help...any suggestion
jgill
12-09-2006, 05:15 PM
Hello,
Here is the code:
<tr>
<tr>
<td class="FormCell">Do you live in US? </td>
<td class="FormCell"><input type="radio" value="true" name="Country">Yes</td>
<td class="FormCell"><input type="radio" value="false" checked name="Country">No</td>
</tr>
<% if true then %>
<td class="FormCell"> This is a test </td>
<td class="FormCell" colspan="2"><select name="TEST">
<option selected value="1">0 to 2500</option>
<option value="2">2,501 to 5,000</option>
<option value="3">5,001 to 8,000</option>
<option value="4">8,001 to 20,000</option>
<option value="5">over 20,000</option>
</select></td>
<% end if %>
</tr>
What I want is that when the page loads the No (Radio Button) is selected (that is by default) and than if the user select the Yes radio button than the dropdown list shows up (TEST).
I guess there r two ways to do that:
• Using DHTML (java script)
• Or some how using the post back function
I will really appreciate yr help. It’s kind of urgent.
Thanks a lot for yr time & effort.
Ricky
so_is_this
12-09-2006, 06:58 PM
To post the form back to itself, make sure the form action points to the current page and add this to both radio buttons:
onclick="this.form.submit(); return true;"
Rusev
12-11-2006, 03:35 AM
Yo dude.It is not a good solution to use any postback's in this case.There is a smart solution :
<style>
.myDivVisible{
display:block;
}
.myDivHidden{
display:none;
}
</style>
<script>
function changeVisibility(isVisible)
{
if (isVisible)
{
document.getElementById('myDiv').class = "myDivVisible";
}
else
{
document.getElementById('myDiv').class = "myDivHidden";
}
}
</script>
Do you live in US?
<input type="radio" onClick="changeVisibility("true");" name="Country">Yes
<input type="radio" changeVisibility("false"); checked name="Country">No
This is a test
<div id="myDiv" class="myDivHidden">
<select name="TEST">
<option selected value="1">0 to 2500</option>
<option value="2">2,501 to 5,000</option>
<option value="3">5,001 to 8,000</option>
<option value="4">8,001 to 20,000</option>
<option value="5">over 20,000</option>
</select>
</div>
But if you use this and make it for crossbrowser platform must be aware that document.getElementById('myDiv').class works in IE, bu for Mozila is document.getElementById('myDiv').className, so you have to check it.
Of course you can do it not in function. but....it's your choice. And it's better to get used with using div's instead of tables.
so_is_this
12-11-2006, 12:39 PM
Yo dude.It is not a good solution to use any postback's in this case.There is a smart solution :
Maybe smart, maybe not. What good is all that code if JavaScript is disabled? In the suggestion I posted, at least there is a regular submit button which would perform the post back for equivalent functionality when JavaScript is disabled.
jgill
12-11-2006, 03:17 PM
Thanks a lot for yr time & the suggestions
Note (Rusev):but I was tiring it out...but now when I run the page with the code…all I see is the 2 radio buttons but nothing happens when I click the YES button…any tips…thanks again…bye
so_is_this
12-11-2006, 04:17 PM
Do you live in US?
<input type="radio" onClick="changeVisibility("true");" name="Country">Yes
<input type="radio" changeVisibility("false"); checked name="Country">No
These:
changeVisibility("true")
should not have quotes around the argument. The second one is also missing some coding. Lastly, for cross-browser support, IE and others use the following:
document.getElementById('myDiv').className = "myDivVisible";
jgill
12-12-2006, 06:12 PM
I was working on the post back method (onclick="this.form.submit(); return true;"). Here is the code:
<td class="FormCell"><input type="radio" value="true" onclick="this.form.submit();return true;" name="test>Yes</td>
<td class="FormCell"><input type="radio" value="false"onclick="this.form.submit();return true;" checked name="test">No</td>
<tr>
if true then
<! -- here is the code for the drop down list that I want to display only when the user clicks YES button -->
end if
</tr>
So please help me out with this…still having problems with it. I can see the radio button & the drop down list when the page load but I want the drop down list to only show if the user clicks YES…thanks a lot for the info so far…appreciate it!
so_is_this
12-12-2006, 08:47 PM
OK, given that your original radio buttons had the name Country, you'd do this:
<% If Request.Form("Country") = "true" Then %>
<td class="FormCell"> This is a test </td>
<td class="FormCell" colspan="2"><select name="TEST">
<option selected value="1">0 to 2500</option>
<option value="2">2,501 to 5,000</option>
<option value="3">5,001 to 8,000</option>
<option value="4">8,001 to 20,000</option>
<option value="5">over 20,000</option>
</select></td>
<% End If %>
jgill
12-18-2006, 06:55 PM
Hello,
Sorry for the late reply was really busy with other stuff…thanks u guys…for the help…it working now…but got few more questions that are???
1)How do I maintain state…that happens is that after post back and value in the dropdown & the radio buttons are not maintained…they go back to default.
2)If I want to call the values (selected in the drop down list) in some other page how do I do that.
Thanks…lot the help is appreciated
so_is_this
12-18-2006, 07:27 PM
1)How do I maintain state…that happens is that after post back and value in the dropdown & the radio buttons are not maintained…they go back to default.
This would go somewhere in the beginning of your page (before you start outputing HTML):
<%
Country = "false"
If Request.ServerVariables("REQUEST_METHOD") = "POST" Then
Country = Request.Form("Country")
End If
%>
Then you would have this (using your original HTML structure):
<tr>
<td class="FormCell">Do you live in US? </td>
<td class="FormCell"><input type="radio" name="Country" value="true"
<% If Country = "true" Then Response.Write "checked" %>>Yes</td>
<td class="FormCell"><input type="radio" name="Country" value="false"
<% If Country = "false" Then Response.Write "checked" %>>No</td>
</tr>
jgill
12-19-2006, 01:44 PM
Hey...still not working...when I click the yes (Radio button) the dropdown list appears (after postback) but the session is still not maintained...the value the yes (Radio button) goes back to no & the value of the drop down list also goes back to the default value...Please help me out...thanks!
so_is_this
12-19-2006, 05:35 PM
Use this debugging version of the code to see what is coming through:
<%
Country = "false"
If Request.ServerVariables("REQUEST_METHOD") = "POST" Then
Country = Request.Form("Country")
End If
Response.Write "<p>" & Request.ServerVariables("REQUEST_METHOD") & ": Country=" & Country & "</p>"
%>
jgill
12-19-2006, 06:15 PM
thanks its working now...looks like u r really good with asp...thats nice...wish i knew a little more...lol...anyway my next question is i want by default to value to be false(no) but once the user makes the selection than the state is maintainded...thanks!
Note: i tried checked name ... but after postback it goes back to the checked name value & overwrite the state...so what else can i try??
so_is_this
12-19-2006, 06:57 PM
Basically, you use this same syntax:
<% If Country = "true" Then Response.Write "checked" %>
If in a drop-down OPTION tag, then you'd code it more like this:
<% If Country = "true" Then Response.Write "selected" %>
The first variable in the IF condition should match the name of the form element. You create that variable as I showed you. The second part of the IF condition is the value of that particular checkbox, radio button, or option. For checkboxes and radio buttons you write "checked" and for options you write "selected".
jgill
12-19-2006, 07:16 PM
what is happening is that when the page loads for the 1st time no radio button is selected but once the selection is made than it stays...I want that No (false) to be selected when the page loads for the 1st time by default...thanks!
so_is_this
12-19-2006, 08:05 PM
The code I supplied does that. So there is something wrong
with the way you have implemented what I posted.