![]() |
autoselect a radio button based on a textbox value
Hi,
How do I get somethng like this out - Auto Select a Radio Button based on a textbox value - I have a textbox value that would generate the getday value ( 0 to 6 ), if its O or 1 - I want the Radio Button 2 to be selected, if its 2 to 6, I want Radio Button 3 to be selected This is my code, right now its returing the Myfunction is undefined error, I think I am not passing some parameters accurately. how do I solve it Code:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Testdate.aspx.cs" Inherits="Test_Testdate" %> |
This should do the trick:-
Code:
<form id ="myform">if(y=0||y=6); // does not comply with what you have asked for. But may be what you actually want - if today is Sunday or Saturday. var x = new Date(document.getElementById("TextBox1").value); value="03/16/2013" is not a valid Javascript date format. The correct format is var theDate = new Date(2013,2,12); // note that in Javascript the months are 0-11 so March is month 2. "Political langauge - and with variations this is true of all political parties from Conservatives to Anarchists - is designed to make lies sound truthful and murder respectable, and to give the appearance of solidity to pure wind". - George Orwell, English novelist and journalist, 1903-1950. |
That ASP.NET code is bogus.
The radio buttons need a GroupName property. And if you use that, then the code can get much simpler: Code:
<html>As Philip pointed out, the correct way to get a date in JS is to use Code:
var dt = new Date( year, month, day );*********** EDIT: Yes, I just tested this, as an ASP.NET page, and it worked. Using Chrome as the browser, no less. |
Oh, also as Philip pointed out: Weekend days in JS are 0 and 6. Not 0 and 1. Unless in your country Sunday and Monday are the weekend.
So if you wanted 0 and 6, Sunday and Saturday, then this line: Code:
if ( dt.getDay() <= 1 )Code:
if ( dt.getDay() === 0 || dt.getDay() === 6 ) |
If anybody is curious, this is the HTML produced by the above ASP.NET code (the page was named "junk1.aspx"):
Code:
<html> |
Hi all
Got it, this is my version, I have parsed the date to another format as well. Code:
function myFunction1() So now, I was thinking of getting the Public Holiday selected. What I have in mind would be cross checking the value in the textbox with a comma delimited text file. If it exists - autoselect Public Holiday, If it does not - check the value of the getday, if its 0 or 6, choose weekend otherwise normal. Please help.... |
Quote:
This is wrong:- else if (databox2.value != "0" || databox2.value != "6") { || should be &&. But just else { will do fine. |
Quote:
You are using ASP.NET, why not use a database?? MUCH better than a CSV file. If you don't want to post back to the server (though ASP.NET encourages you to do so), use AJAX. |
Hi Old Pendant
Actually, I am confused ..on using Javascript or asp.net. Its just that I have got the rest of it in javascript done. I was just thinking of adding this ajax code with the javascript. If I do use asp.net to do it, how will I be parsing the value to the javascript that I have created. Hi Philip M, I have found the ajax code to read the text file, here is the code Code:
<script language="JavaScript" type="text/javascript"> |
Nope, that won't come close to working.
You can't use document.write() in an AJAX function. You can't use it in *ANY* code that executes after the page is fully loaded. Period. Once again, if you are going to use AJAX, why not connect it to ASP.NET code and thus to a database?? Code:
function checkForHoliday( dateToTest ) |
As you are relying on Javascript I see no reason why you should not include the array of public holiday dates in your .js file. No need for Ajax or a database. However you do it you will still have to update the public holidays annually (or periodically).
Code:
<body onload = "whatday()"> |
I agree on this one. If you aren't going to do the whole enchilada, getting all holidays for the last 100 years and the next 100 years, then why bother with either a DB or CSV file? Just dump them directly into the JS code. Or, at a minimum, use a JS include.
Code:
<script type="text/javascript" src="arrayOfHolidays.js" /> |
| All times are GMT +1. The time now is 01:56 PM. |
Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.