Cannot assign to a function result javascript

Trying to create a date validation..

Page 1 of 1

2 Replies - 6074 Views - Last Post: 21 June 2010 - 09:17 AM

#1 Arshan  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 22
  • Joined: 11-October 07

Cannot assign to a function result javascript

Posted 18 June 2010 - 01:44 PM

Hi all,

Trying to create a date validation form; since most don't do what I need. So far it's doing ok; I'll admit I found a lot of the code on the web, but I wanted to add it where it would automaticly change the string entered (Example if a user did 3/5/2010, it would make it 03/05/2010). Well getting the month was easy, however I'm having trouble fixing the date.

Here is the problem section. ValDate is called from the validation function.
 if (ValDate.substring(4,5) = '/')
    {
    var newdatea;
    var newdateb;
	newdatea = ValDate.substring(0,5)
	newdateb = ValDate.substring(5,10)
	sDate = newdatea + '0' + newdateb;
	alert(newdate);
}


That gives me the error you see above
- Cannot assign to a function result javascript

Here I though i was being clever too but apparently I missed something. Amy help is appreciated :)

Is This A Good Question/Topic? 0
  • +

Replies To: Cannot assign to a function result javascript

#2 JohnWaters  Icon User is offline

  • D.I.C Head

Reputation: 11
  • View blog
  • Posts: 138
  • Joined: 28-November 08

Re: Cannot assign to a function result javascript

Posted 18 June 2010 - 02:08 PM

Hey,

I'm not exactly sure if this is the approach I would normally take but I think you're trying for something like ...

function validate_Date(myDate){
	var delimiter = "/";
	var myArray = myDate.split(delimiter);
	if(myArray.length < 3){
		alert("Date Error")
	} else {
		var newDate = "";
		for(var i=0;i<myArray.length;i++){
			newDate += ((myArray[i].length < 2)?"0"+myArray[i]:myArray[i]);
			if(i < (myArray.length-1)){
				newDate+= delimiter;
			}
		}
		return newDate;
	}
}



I didn't test this but I'm sure you can tweak it to what you need. :bigsmile:

Note: In relation to the error you are getting, I cant be sure because you haven't give us enough code BUT I can only guess that your function name is the same as one of those variables.

This post has been edited by JohnWaters: 18 June 2010 - 02:31 PM

Was This Post Helpful? 0
  • +
  • -

#3 Arshan  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 22
  • Joined: 11-October 07

Re: Cannot assign to a function result javascript

Posted 21 June 2010 - 09:17 AM

Hi, thanks for the reply, wasn't at work so i didn't get a chance to get back to you.

I ended up figuring out what was wrong it was a pretty dumb mistake; but for the if statement I used = instead of == so it was trying to assign the value there. I'm to used to working with vbscript so I keep forgetting you need double = in java script.

Thanks for the sample too; I was able to modify it a little bit to make my code a little more efficient as well. :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1