...

View Full Version : onchange problem



chrisboots
01-21-2012, 01:48 PM
I need the code to run a few functions on change, the box is a "date picker" and I unsure how to add my onchange function without breaking the date picker, can anyone help ?


p>end date:</p>
<input id='secondDate' type="text" size="25"><a href="javascript:NewCal('secondDate','ddmmyyyy')"><img src="images/cal.gif" width="16" height="16" border="0" alt="Pick a date" onchange="dateDiff() ;calculate() ;deposit() ;milecharge() ;agecheck()"></a>

xelawho
01-21-2012, 03:20 PM
it's almost impossible (for me, anyway) to say, given the snippet provided... it looks OK - do you have a link to a page, or at least a sample of the relevant code?

on a personal note, I think that using onchange for text boxes is generally a bad idea as it is quite unintuitive... onkeyup tends to work better for me in almost all circumstances, if for some reason you do not want to have a button the user can press that will call those functions.

chrisboots
01-21-2012, 03:35 PM
it's almost impossible (for me, anyway) to say, given the snippet provided... it looks OK - do you have a link to a page, or at least a sample of the relevant code?

on a personal note, I think that using onchange for text boxes is generally a bad idea as it is quite unintuitive... onkeyup tends to work better for me in almost all circumstances, if for some reason you do not want to have a button the user can press that will call those functions.


the site is http://www.pennycarhire.co.uk/price.html i want it to run all the function whenever anyone changes the date input box, but i cant seem to get it working

felgall
01-21-2012, 10:45 PM
With an input field you should use onkeyup if you want to test every keypress or onblur if you want to test when they leave the field.

You should only use onchange with select lists.

chrisboots
01-22-2012, 02:41 PM
With an input field you should use onkeyup if you want to test every keypress or onblur if you want to test when they leave the field.

You should only use onchange with select lists.


I have tried every "on " function i can find, the problem is that they dont click on the textbox its self, they click on the little calendar box next to it but no matter where i put any function, it still dose not work, even using google chromes inspect thing, it says its running the function, which it dose, it will run it when the click on the text box, but they don click the textbox at all, thats the problem i got

also onkeyup wont work as there is no need to use a keyboard on my script

xelawho
01-22-2012, 02:41 PM
you should theoretically be able to put this:


winCal.onbeforeunload=function (){
if(pCtrl=='secondDate'){
dateDiff();
calculate();
deposit();
milecharge();
agecheck()
}
}

at the end of your NewCal function to call those functions when the pop up window is closed. Works fine in FF and Chrome, no dice in IE or Opera. Dunno why - maybe somebody does.

xelawho
01-24-2012, 04:55 AM
... at the end of your GenCell function you can change your PCellStr line to:


PCellStr="<td "+vColor+" width="+CellWidth+" align='center'><font face='verdana' size='2'"+vHLstr1+"<a class='calLink' href=\"javascript:winMain.document.getElementById('"+Cal.Ctrl+"').value='"+Cal.FormatDate(PValue)+"';"+vTimeStr+"window.opener.checkDats('"+Cal.Ctrl+"');window.close();\">"+PValue+"</a>"+vHLstr2+"</font></td>";


and then put this anywhere:


function checkDats(tb){
if(tb=='secondDate'){
dateDiff();
calculate();
deposit();
milecharge();
agecheck();
}
}


works in all the abovementioned browsers :thumbsup:

chrisboots
02-09-2012, 02:48 PM
... at the end of your GenCell function you can change your PCellStr line to:


PCellStr="<td "+vColor+" width="+CellWidth+" align='center'><font face='verdana' size='2'"+vHLstr1+"<a class='calLink' href=\"javascript:winMain.document.getElementById('"+Cal.Ctrl+"').value='"+Cal.FormatDate(PValue)+"';"+vTimeStr+"window.opener.checkDats('"+Cal.Ctrl+"');window.close();\">"+PValue+"</a>"+vHLstr2+"</font></td>";


and then put this anywhere:


function checkDats(tb){
if(tb=='secondDate'){
dateDiff();
calculate();
deposit();
milecharge();
agecheck();
}
}


works in all the abovementioned browsers :thumbsup:

I cant get this to work, im not sure which line to replace it with, but it seems which ever one i do, its stops the script as it wont let you select a date


function GenCell(pValue, pHighLight, pColor, pClickable)
{ //Generate table cell with value
var PValue,
PCellStr,
PClickable,
vTimeStr;

if (!pValue)
{
PValue = "";
}
else
{
PValue = pValue;
}

if (pColor === undefined)
pColor = CalBgColor;

if (pClickable !== undefined){
PClickable = pClickable;
}
else{
PClickable = true;
}

if (Cal.ShowTime)
{
vTimeStr = ' ' + Cal.Hours + ':' + Cal.Minutes;
if (Cal.ShowSeconds)
{
vTimeStr += ':' + Cal.Seconds;
}
if (TimeMode === 12)
{
vTimeStr += ' ' + Cal.AMorPM;
}
}

else
{
vTimeStr = "";
}

if (PValue !== "")
{
if (PClickable === true) {
if (Cal.ShowTime === true)
{ PCellStr = "<td id='c" + PValue + "' class='calTD' style='text-align:center;cursor:pointer;background-color:"+pColor+"' onmousedown='selectDate(this," + PValue + ");'>" + PValue + "</td>"; }
else { PCellStr = "<td class='calTD' style='text-align:center;cursor:pointer;background-color:" + pColor + "' onmouseover='changeBorder(this, 0);' onmouseout=\"changeBorder(this, 1, '" + pColor + "');\" onClick=\"javascript:callback('" + Cal.Ctrl + "','" + Cal.FormatDate(PValue) + "');\">" + PValue + "</td>"; }
}
else
{ PCellStr = "<td style='text-align:center;background-color:"+pColor+"' class='calTD'>"+PValue+"</td>"; }
}
else
{ PCellStr = "<td style='text-align:center;background-color:"+pColor+"' class='calTD'>&nbsp;</td>"; }

return PCellStr;
}



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum