Here’s the basic flow of the webpage I’m working on:
- User clicks a button, date /time picker pops up (works).
- A time string fills a textbox, say, 4:00 AM (works).
- User then has to select one of two radio buttons, which should read the time in the text box, radiobutton1 adds 4 hours, radiobutton2 adds 4.5 (does not work).
- The total hours is then displayed in another textbox (haven’t gotten to this yet).
Other than the 1st item (which retrieves the dates from a server), most of the work is done by Javascript.
So here’s the Javascript I’m working on:
function setHours(setting)
{
var tempVal = document.getElementById('<%=Text6.ClientID%>');
var nHours;
var textHours = new DateTime(tempVal);
alert(tempVal);
textHours = getHours
if (setting==true) {
nHours = 4;
alert("4");
}
else {
nHours = 4.5
alert("4.5");
}
textHours.setHours(textHours.getHours() + nHours);
document.getElementById("text8").value = textHours;
}
This function is called when the user clicks on either one of the two radiobuttons (one passes true, the other passes false). Notice that I have “alert”s scattered throughout, because initially, I couldn’t get the entire function to fire. So I commented out everything but the “if statements” and the “alert”s, and lo and behold it works fine.
I’m assuming the problem is somewhere in the var, perhaps, how “tempVal” retrieves the value in text6.
Here’s the code for the textbox.
<form id='frmRequestApplicationForm' name='frmRequestApplicationForm' action='#' method='post'>
<input class="textboxdefault" type="text" name="Starttime" id="Text6" value="<%=(requestApplicationForm.StartimeError.ToString().Equals("")?requestApplicationForm.StarttimeDate.ToShortDateString().Equals("1/1/0001")?"":requestApplicationForm.StarttimeDate.ToShortTimeString(): requestApplicationForm.Starttime)%>"/>
</form>
Building the program nets me a “Text6 does not exist”. I’m not sure where the code refuses to work.
Replacing “<%=Text6.ClientID%>” with a simple “Text6” makes the entire Javascript function fail.
Could I have some help on this?
Nevermind.
I replaced “
document.getElementById('<%=Text6.ClientID%>');” withSeems to work fine now.