Firstly thanks to DigitalPoint and its users for providing me many help and solution previously. I have a new problem. I have the following form that have a date field with date vale. <form name="signup" onsubmit="return Valid(this);"> <input type="text" name="date" value="09/22/2011"> <input type="submit"> </form> I need a JavaScript that will take the date value on form submit and split it to 3 parts (such as month, day, year) and then return. So that I can insert separately these 3 parts in my MySql table (3 fields) during the form submit. Like bellow: Month Day Year ------ ----- ------ 09 22 2011
This should be done by server side... But if you need this functionallity in javascript, you can use: var foo = "09/22/2011"; var arr = foo.split("/"); alert(arr[0]) alert(arr[1]) alert(arr[2]) Code (markup):
Yea, I think using PHP would be best for this, but if you are using a JS calendar or any other type of JS to handle it then you will want to use the .split function like in the example above.
I have some code like below, What is wrong on it ? I am getting error. onClick: function () { $.ajax({ type: 'POST', url: 'http://www.mysite.com/data.php', dataType: 'json', success: function (data) { var res = []; for (var i in data) { var rows = data; res.push({ event_id: rows[0], event_name: rows[1], date: rows[2], venue:rows[3], url:rows[4], }); var eventdate = $data.date; var splitdate = eventdate.split("-"); year = splitdate[0], month = splitdate[1], day = splitdate[2] if (month == 01) { month = "Jan" } if (month == 02) { month = "Feb" } if (month == 03) { month = "Mar" } var newDate = year - month - day; } viewModel.dSource(res); } }); }